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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://521701]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 04:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found