Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: sort based upon the partial data

by nagalenoj (Friar)
on Mar 03, 2009 at 10:06 UTC ( #747662=note: print w/ replies, xml ) Need Help??


in reply to sort based upon the partial data

#!/usr/bin/perl use warnings; sub func { $a =~ s/.*_(\d+)$/$1/; $b =~ s/.*_(\d+)$/$1/; $a <=> $b; } my @array = ("0x4b82_555","0x4b82_5", "0x4b82_58","0x4b82_651", "0x4b8 +2_551"); my @result = sort func @array; print "@result";

The above code will give the result as you want.


Comment on Re: sort based upon the partial data
Download Code
Re^2: sort based upon the partial data
by shmem (Canon) on Mar 03, 2009 at 10:12 UTC

    That technique is called "destructive sort" :-P

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2015-07-02 10:51 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 (34 votes), past polls