Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Changing Perl's sort Default

by fglock (Vicar)
on Oct 23, 2002 at 20:00 UTC ( #207512=note: print w/replies, xml ) Need Help??

in reply to Changing Perl's sort Default

This is one way to "change the default", but i think is a bit odd:

sub sort { sort { $a <=> $b } @_ } @a=qw(1 12 11 102); @a = &sort (@a); print "@a";' Output: 1 11 12 102

It works because &sort calls main::sort, instead of CORE::sort

Replies are listed 'Best First'.
Re: Re: Changing Perl's sort Default
by fglock (Vicar) on Oct 24, 2002 at 13:15 UTC

    This is the "numerical + alphabetical" version:

    sub sort { sort { ($a <=> $b) or ($a cmp $b) } @_ } @a=qw( 1 12 11 102 ddd abc cba 1c 1a ); @a = &sort (@a); print "@a\n"; Output: abc cba ddd 1 1a 1c 11 12 102

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2022-12-05 11:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found