Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://521701]
help
Chatterbox?
[robby_dobby]: Every time I fall asleep, there's a small guy in the dreams, shouting "Whoo!" and it jolts me awake. :/
[Lady_Aleena]: robby_dobby, at least you aren't driving. I seem to always be driving somewhere in my dreams and end up at a weird house.
[robby_dobby]: LA: That's there. But this is work and it's the same thing as falling asleep driving :-)
[Lady_Aleena]: I love the dream where I was at a huge house and decided to go swimming in the pool, but then the tour group showed up.
choroba fell asleep while driving half a year ago
[choroba]: fortunately, only the traffic sign and the car were damaged

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-05-29 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?