in reply to Re^3: merge with multiple row with same key
in thread merge with multiple row with same key
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: merge with multiple row with same key
by Laurent_R (Canon) on Nov 27, 2014 at 07:12 UTC | |
|
Re^5: merge with multiple row with same key
by davido (Cardinal) on Nov 27, 2014 at 07:18 UTC |