Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: two questions that come together into one grand unified question

by premchai21 (Curate)
on Oct 15, 2001 at 07:58 UTC ( [id://118811]=note: print w/replies, xml ) Need Help??


in reply to sorting and comparing hashes

No, the sorting would not work if they were arrays. Read sort again and you'll see why. Not only that, but hashes are by definition sorted by hash, that is, sorted in a manner only meaningful to the interpreter, probably not to you. However, arrays may or may not be sorted. The problem is that the sort function is non-destructive; it won't sort an array in place, but rather return a new array, which is sorted.

Now as for the second problem, I assume you want to print to TEST the contents of playlist, and TEST2 the contents of filelist, with the keys sorted ASCIIbetically. Then you need two for loops:

for (sort keys %playlist) { print TEST "$playlist{$_}\n" } for (sort keys %filelist) { print TEST2 "$filelist{$_}\n" }

Now if you want the values sorted instead, then you need to do:

for (sort values %playlist) { print TEST "$_\n" } for (sort values %filelist) { print TEST2 "$_\n" }

HTH.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found