SPUG: Sorting Files by Mod. Times
Dean Hudson
dean at ero.com
Wed Oct 6 23:14:00 CDT 1999
On Wed, 6 Oct 1999, Scott Blachowicz wrote:
> %mod_time = ();
> @links = sort {
> ($mod_time{$a} || ($mod_time{$a} = (stat $a)[9])) <=>
> ($mod_time{$b} || ($mod_time{$b} = (stat $b)[9]));
> } @links;
Here's a solution I posted to clp.misc a while ago, it basically does what
you've got above in the current directory over a for loop, and prints
pretty(ish) output.
It's been tested. Hope it helps.
# ----- code ----- #
#!/usr/bin/perl -w
use strict;
my ( %m );
for ( sort { ( $m{$b} ||= (stat($b))[9] ) <=>
( $m{$a} ||= (stat($a))[9] ) } <*> )
{
my ( $day, $mon, $yr );
( $day, $mon, $yr ) = ( localtime $m{$_} )[3..5];
print "$_ => d:$day m:", $mon + 1, " y:", 1900 + $yr, "\n";
}
# ----- code ----- #
dean.
--
dean hudson, <deanh at ero.com>
research fellow, esoteric research organization
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list