in reply to Push Function and Hash
Once you have your files read in using push(@{$health{$patient}},$level); you should end up with a structure like so:
You can then iterate through the hash of arrays using while or for:%health = ( 'John Kay' => [151,128], 'Sally Gi' => [174,145], );
Output:while ( my ($patient,$levels) = each %health ) { my @ascending = sort {$a <=> $b} @$levels; print "$patient: @ascending\n"; } for my $patient ( keys %health ) { my $levels = $health{$patient}; my @descending = sort {$b <=> $a} @$levels; print "$patient: @descending\n"; }
John Kay: 128 151 Sally Gi: 145 174 John Kay: 151 128 Sally Gi: 174 145
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Push Function and Hash
by eepvesity (Initiate) on Mar 28, 2013 at 15:04 UTC |
In Section
Seekers of Perl Wisdom