Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: providing a callback routine to sort

by pemungkah (Priest)
on Jan 21, 2014 at 22:04 UTC ( [id://1071530]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $dir = shift; 
    
    my $sort_sub = $dir eq 'up' ? sub {$a <=> $b} : sub {$b <=> $a};
    my @items = (3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5);
    print "@{[sort { $sort_sub->() } @items]}\n";
    
  2. or download this
    $ perl sample up
    1 1 2 3 3 4 5 5 5 6 9
    $ perl sample down
    9 6 5 5 5 4 3 3 2 1 1
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-24 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found