Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Challenge: sort weekdays in week-order (Sort::Key)

by LanX (Saint)
on Jul 21, 2022 at 15:25 UTC ( [id://11145637]=note: print w/replies, xml ) Need Help??


in reply to Challenge: sort weekdays in week-order (elegantly and efficiently)

Using Salva's Sort::Key is efficient and elegant, but I can't get rid of the order info
use v5.12; use warnings; use Sort::Key qw/ikeysort/; use Data::Dump qw/pp dd/; my $n; my %order = map {$_ => ++$n} qw/monday tuesday wednesday thursday friday saturday sunday/; pp ikeysort { $order{lc($_)} } qw/Monday Saturday Thursday/;

==>

("Monday", "Thursday", "Saturday")

edit
oops wait, there is a bug...

update

Fixed bug in %order creation

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-24 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found