Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

james2vegas's scratchpad

by james2vegas (Chaplain)
on Aug 08, 2009 at 01:11 UTC ( #786972=scratchpad: print w/ replies, xml ) Need Help??

my %sorts = ( 'case sensitive forward' => sub { $_[0] cmp $_[1] }, 'case insensitive forward' => sub { uc $_[0] cmp uc $_[1 +] }, 'case sensitive backward' => sub { $_[1] cmp $_[0] }, 'case insensitive backward' => sub { uc $_[1] cmp uc $_[0 +] }, 'case sensitive forward reverse' => sub { reverse($_[0]) cmp r +everse($_[1]) }, 'case insensitive forward reverse' => sub { uc reverse($_[0]) cm +p uc reverse($_[1]) }, 'case sensitive backward reverse' => sub { reverse($_[1]) cmp r +everse($_[0]) }, 'case insensitive backward reverse' => sub { uc reverse($_[1]) cm +p uc reverse($_[0]) }, ); # 5.10+ only #sub do_sorts { # state %cache; # my $res = $cache{$_[0], $_[1]}; # return if defined($res); # foreach my $sort (@{$_[2]}) { # $res ||= $sorts{$sort}->(@_) # } # $cache{$_[0], $_[1]} = $res #} { my %cache; sub do_sorts { my ($first, $second, @sort_list) = @_; my $res = $cache{$first, $second}; return $res if defined($res); foreach my $sort (@sort_list) { $res ||= $sorts{$sort}->($first, $second); last if $res } $cache{$first, $second} = $res } } my @list = qw(foo Bar baz Fuzz); print join(', ', sort { do_sorts($a,$b,('case sensitive forward revers +e')) } @list)."\n";
XML-Parser/Parser.pm#HANDLERS
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2015-07-06 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls