Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-06-24 01:59 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (556 votes). Check out past polls.