我有以下數據,我需要將第二列作爲標題。任何幫助表示讚賞。重新排列數據從一列到一行
數據:
IBM,Voltality,7,73894756.93897434897
IBM,Market,100,983874.34324
GOOG,Sanity,15,8932748
GOOG,Rate Jump,25,873476378.234234
MBLY,Market,340,23423423432.6783
輸出:
PRODUCT|Market|Rate Jump|Sanity|Voltality
IBM|100,983874.34324|||7,73894756.93897434897
GOOG||25,873476378.234234|15,8932748|||
MBLY|340,23423423432.6783|||
代碼(不完整/不知道燙去年底):
#!/usr/bin/perl
use strict;
use Getopt::Long;
use warnings;
use Data::Dumper;
my $valsep = ',';
my (%type, %keys, %ccy, %cnt, %avg);
while (<>) {
chomp;
my ($product, $reason, $count, $lat) = split /,/;
my $key = "$product,$reason";
if (not exists($type{$reason})) {
$type{$reason} = $reason;
}
$ccy{$key} = $product;
$cnt{$key} = $count;
$avg{$key} = $lat;
}
close(INPUT);
print Dumper (\%ccy);
print Dumper (\%type);
my (%pair, %details);
foreach my $rows (sort keys %ccy) {
print "the key is : $rows and $ccy{$rows}\n";
foreach my $res (sort keys %type) {
print "The type is : $res and $type{$res}\n";
}
}
你可能忘記從你的第一個試驗提到你的代碼來解決這個 – 2014-10-18 19:33:18
我就不能完成。以下是我到目前爲止所得到的結果。 – Tinman 2014-10-18 19:40:24