My apologies. Let me give you more details on this. Basically, I have routine to read a file(test.out) where the file format is:
Then my code isA,B*,item2,, A,B*item1,,, A,B*,,,item4 C,D*item1,,, C,D*,,item3,
sub merge { open(INFILE, "test.put"); my %data; while (<INFILE>) { chomp; my ($key,@items) = split(/\*/); $data{$key}{$_}++ for @items; } close INFILE; print Dumper(\%data); }
The Dumper shows
$VAR1 = { 'C,D' => { ',,item3,' => 1, 'item1,,,' => 1 }, 'A,B' => { ',,,item4' => 1, ',item2,,' => 1, 'item1,,,' => 1 } };
If I want to merge the rows under key (e.g. 'C,D") to reformat and write into file, what should I do then? many thanks
C,D,item1,,item3, A,B,item1,item2,,item4
In reply to Re^4: merge with multiple row with same key
by tcheungcm
in thread merge with multiple row with same key
by tcheungcm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |