sort directory help

J

Jake Wiley

I need to sort a directory which is all fine BUT my directory names are
all in date formats like Nov 18 2004, Dec 23, 2005 etc.. The simple
sort works BUT like this:
Aug 5 2004
Dec 1 2004
Dec 8 2004
Jan 2 2005
Nov 7 2004

I want to get the folders in chronological order. It's for a backup
program and I want to be able to delete the oldest folder after a
couple of weeks. Could somebody please point me in the right direction
or perhaps a module that does this. Thanks
 
J

Jake Wiley

Thanks for the info Nathan

I tried your sample Jim Gibson and It looks like it's trying to work
but only after several of these messages:
Use of uninitialized value in numeric comparison (<=>) at blah blah
blah line 14
which was this line :

map{ $_->[0] }

After that the ouput was Aug 5 2004 Nov 7 2004 etc in chronological
order. Thats what I needed.. :)

Here is my modified piece.
opendir(DIRHANDLE, "E:\\Backup") or die "couldn't open E:\\Backup :
$!";
my @dates = readdir(DIRHANDLE);
my @sorted =
map{ $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, parsedate($_)] } @dates;
print @sorted;

Why the error message about "Use of uninitialized value in numeric
comparison (<=>)"
 
T

Tad McClellan

Jake Wiley said:
my @sorted =
map{ $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, parsedate($_)] } @dates;
Why the error message about "Use of uninitialized value in numeric
comparison (<=>)"


Because parsedate() returned undef.

Consult the function's documentation to see why it
might do that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top