No need for that, just tweak the "tr" a little :)
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11145633 use warnings; use List::AllUtils qw( shuffle sort_by ); my @weekdays = shuffle qw/Monday tuesday wednesday friday sunday Saturday Thursday/; print "$_\n" for sort_by { lc =~ tr/muwht/a-d/dr } @weekdays; # Monday + first print "\n"; print "$_\n" for sort_by { lc =~ tr/nmewhfatsu/a-g/dr } @weekdays; # S +unday first
In reply to Re^4: Challenge: sort weekdays in week-order (elegantly and efficiently)
by tybalt89
in thread Challenge: sort weekdays in week-order (elegantly and efficiently)
by bliako
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |