Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: How can I sort this data on the first field

by Chady (Priest)
on Apr 26, 2005 at 06:19 UTC ( #451432=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How can I sort this data on the first field
in thread How can I sort this data on the first field

It's not a hash that you want... it's probably an array of arrays. What if there were duplicate keys? your hash will eat them up and you'll end up with only the last entry.

compare:
print "With Hash:\n\n"; $save = tell DATA; while(<DATA>) { my ($k, $v) = split '\|'; $hash{$k} = $v; } print "$_|$hash{$_}" for sort { $a <=> $b } keys %hash; seek DATA, $save, 0; print "\n\nWith array:\n\n"; while(<DATA>) { my ($k, $v) = split '\|'; push @arr, [$k, $v]; } print "$_->[0]|$_->[1]" for sort { $a->[0] <=> $b->[0] } @arr; __DATA__ 30|microsoft 70|aol 76|netscape 5|trouble? 35|mozilla 30|die microsoft 40|opera 100|FireFox 5|no more trouble

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/
Are you a Linux user in Lebanon? join the Lebanese GNU/Linux User Group.


Comment on Re^3: How can I sort this data on the first field
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-11-27 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (186 votes), past polls