1825576 Members
1953 Online
109682 Solutions
New Discussion

Perl Sorting Question

 
SOLVED
Go to solution
Jason Berendsen
Regular Advisor

Perl Sorting Question

I am trying to do a sort on file access time of a directory on a Windows NT direcotry. I can get the atime and the file name, but when I do a sort it always defaults to an ASCII sort on the filename. How do I do a numeric sort on the atime field? Is there an easy way to sort numerically on a specific field in Perl?
2 REPLIES 2
Elmar P. Kolkman
Honored Contributor
Solution

Re: Perl Sorting Question

Outside of perl, it would be the option -n to the sort command. And if the time is not on the begin of the line but in column 2 it would become
sort -nk2

But I guess more info on how the list of data looks might help us to give you a algorithm to do what you want...
Every problem has at least one solution. Only some solutions are harder to find.
H.Merijn Brand (procura
Honored Contributor

Re: Perl Sorting Question

my @list = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, (stat)[8] ] }
glob "*.html";

that's all

search doc's for swarzian transform


sort { $a <=> $b } ...

is sort ascending numerical. swap a and b for descending

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn