Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Push Function and Hash

by tangent (Priest)
on Mar 28, 2013 at 01:32 UTC ( #1025832=note: print w/ replies, xml ) Need Help??

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"; }
John Kay: 128 151 Sally Gi: 145 174 John Kay: 151 128 Sally Gi: 174 145

Comment on Re: Push Function and Hash
Select or Download Code
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025832]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2016-02-09 06:08 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (304 votes), past polls