Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: sorting out directories

by sk (Curate)
on Jan 07, 2006 at 08:22 UTC ( #521701=note: print w/ replies, xml ) Need Help??


in reply to sorting out directories

Tanktalus's suggestion is a better to handle this problem. But if you want something quick and dirty, you can do something like this -

#!/usr/bin/perl -w use strict; my $base = "ca"; my @dirs = map { $base . int (rand 100) } (1..10); # Instead of matching for $base (ca) you can also match characters etc +. This approach works for simple things and can get complex quickly my @sorted = sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] } map { [/($base)(\d+)/] } @di +rs; @sorted = map { $_->[0] . $_->[1] } @sorted; print $_, $/ for (@dirs); print $/; print $_, $/ for (@sorted);

Output

ca58 ca43 ca98 ca83 ca11 ca59 ca54 ca92 ca69 ca30 ca11 ca30 ca43 ca54 ca58 ca59 ca69 ca83 ca92 ca98


Comment on Re: sorting out directories
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-01 21:52 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 (22 votes), past polls