Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Push Function and Hash

by tangent (Deacon)
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"; }
Output:
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
Re^2: Push Function and Hash
by eepvesity (Initiate) on Mar 28, 2013 at 15:04 UTC
    Appreciate the response.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-09-30 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (385 votes), past polls