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

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 scrutinizing the Monastery: (11)
As of 2015-11-25 21:23 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (691 votes), past polls