
Chris Charley
User
Oct 30, 2012, 11:53 AM
Post #3 of 4
(3460 views)
|
Re: [CPS] Identical key names in hash array?
[In reply to]
|
Can't Post
|
|
Here is and example of a hash of arrays. The first part creates it and the second part prints it out.
#!/usr/bin/perl use strict; use warnings; my %data; while (<DATA>) { my ($key, $val) = split; push @{ $data{$key} }, $val; } use Data::Dumper; print Dumper\%data; for my $key (sort keys %data) { for my $val (@{ $data{$key} }) { print "$key $val\n"; } } __DATA__ AAA 50 BBB 40 CCC 90 BBB 65 It produced the following output.
C:\Old_Data\perlp>perl t7.pl $VAR1 = { 'CCC' => [ '90' ], 'BBB' => [ '40', '65' ], 'AAA' => [ '50' ] }; AAA 50 BBB 40 BBB 65 CCC 90
|