http://www.perlmonks.org?node_id=1025832


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:
%health = ( 'John Kay' => [151,128], 'Sally Gi' => [174,145], );
You can then iterate through the hash of arrays using while or for:
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"; }
Output:
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
    Appreciate the response.