Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: a proper sort

by dragonchild (Archbishop)
on Mar 04, 2005 at 14:51 UTC ( #436584=note: print w/replies, xml ) Need Help??


in reply to a proper sort

You want to change your sort to
@pretty=sort { my @a = $a =~ /(\D+)(\d+)?/; my @b = $b =~ /(\D+)(\d+)?/; $a[0] cmp $b[0] || ($a[1] || 0) <=> ($b[1] || 0) } @not_so_pretty;

Right now, your regex will fail to provide anything in @a/@b if there aren't any numbers.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: a proper sort
by ministry (Scribe) on Mar 04, 2005 at 15:21 UTC
    Brilliant! This works perfectly.

    I had been trying for days to firgure this one out - thank you so much.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2023-10-02 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?