in reply to Re^2: Appending values to existing hash key
in thread Appending values to existing hash key
Hi jaypal,
i totally agreed with ++NetWallah and really you can use a map for the nested for loop like so:
use warnings; use strict; my %hash; while (<DATA>) { my @data = split; push @{ $hash{ $data[0] }{ $data[1] } } => "$data[2]: $data[3]"; } for my $key ( sort keys %hash ) { print $key, ' ', join( ', ' => map { $_, @{ $hash{$key}{$_} } } keys %{ $hash{$ke +y} } ), $/; } __DATA__ id1 name1 cat1 catname1 id1 name1 cat2 catname2 id2 name2 cat3 catname3 id3 name3 cat1 catname1 id3 name3 cat4 catname4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Appending values to existing hash key
by NetWallah (Canon) on Mar 21, 2014 at 04:47 UTC | |
by 2teez (Vicar) on Mar 21, 2014 at 06:56 UTC | |
|
Re^4: Appending values to existing hash key
by jaypal (Beadle) on Mar 21, 2014 at 04:31 UTC |