Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Sort on Number Embedded in String

by tlm (Prior)
on Mar 23, 2005 at 13:45 UTC ( [id://441762]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @sorted = sort { property($a) <=> property($b) } @unsorted;
    
  2. or download this
    ($foo, $bar, $baz, ...)
    
  3. or download this
    { property($a) <=> property($b) }
    
  4. or download this
    ([$foo, property($foo)], [$bar, property($bar)], [$baz, property($baz)
    +], ... )
    
  5. or download this
    { $a->[1] <=> $b->[1] }
    
  6. or download this
    my @st        = map  { [ $_, property($_) ] } @files;
    my @sorted_st = sort { $a->[1] <=> $b->[1] }  @st;
    my @sorted    = map  { $_->[0] }              @sorted_st;
    
    sub property { ( $_[0] =~ /fwlog\.(\d+)\w+/ )[ 0 ] };
    
  7. or download this
    my @sorted =
      map  { $_->[0] }
      sort { $a->[1] <=> $b->[1] }
      map  { [ $_, ( $_[0] =~ /fwlog\.(\d+)\w+/ )[ 0 ] ] }
      @files;
    
  8. or download this
      sort { $a->[1] <=> $b->[1] or
             $a->[2] cmp $b->[2] or
             $b->[3] <=> $a->[3] }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-18 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found