BhariD has asked for the wisdom of the Perl Monks concerning the following question:
I have this section of code to fill hash into an array
my (@array); while(<IN>){ chomp $_; my @cols = split("\t", $_); my $data = join("\t", $cols[2], $cols[5]); push (@array, {$cols[0]=>$data}); # to keep multiple entries for the +same key } close(IN); foreach my $key(@array){ foreach my $value(keys %$key){ print $value, "\t", $key->{$value}, "\n"; #here how can I join values for the same key? #similar to OUTPUT shown below } } INPUT p1 cis 10 p1 plat 20 p1 gls NA p2 cis 0 p2 NA 9 OUTPUT p1 cis,plat,gls 10,20,NA p2 cis,NA 0,9
I would appreciate any help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to join values of the same key that is an array of hashes?
by toolic (Bishop) on Jan 04, 2014 at 15:04 UTC | |
|
Re: How to join values of the same key that is an array of hashes?
by kcott (Archbishop) on Jan 05, 2014 at 08:16 UTC | |
|
Re: How to join values of the same key that is an array of hashes?
by Anonymous Monk on Jan 05, 2014 at 04:18 UTC |