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

Re: Sorting Criteria

by Aristotle (Chancellor)
on Aug 05, 2003 at 18:04 UTC ( #281109=note: print w/replies, xml ) Need Help??


in reply to Sorting Criteria

  1. You don't return the elements from the sort block, you return -1, 1 or 0 depending on whether $a or $b was greater or they were equal. See perldoc -f sort.

  2. You don't need to pass $a / $b explicitly that way, they're special globals.

  3. In fact, you even shouldn't, since $a / $b are aliases, and you're reassigning to them a copy of their value at the top of your block. Alternatively, assign them to lexicals named differently from $a / $b. In your case, I'd just drop the shifts, call the function by_date and then say

    @sorted = sort &by_date keys %reversed;

Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2022-12-08 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?