Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Command line file sorting

by Anno (Deacon)
on Sep 05, 2007 at 17:55 UTC ( [id://637227]=note: print w/replies, xml ) Need Help??


in reply to Command line file sorting

I don't see much room for simplification. The map block could be replaced by a slightly simpler expression:
map [ m|/dir-(\d+)-(\d+)$|, $_], @ARGV
Note the anchor to then end of string in the regex. It makes sure that earlier combinations of digits and "-" in the path don't mess up the capture.

Also, xargs isn't the right tool to use here. It splits the arguments into portions if there are too many, but you need to sort the entire list in any case. So my suggestion would be

perl -le'print( (sort {$b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] } ma +p [ m|/dir-(\d+)-(\d+)$|, $_], @ARGV)[1]->[2])' ./dir-*
Anno

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-25 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found