Skip to content

Instantly share code, notes, and snippets.

@AndrewRussellHayes
Last active December 28, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRussellHayes/7570057 to your computer and use it in GitHub Desktop.
Save AndrewRussellHayes/7570057 to your computer and use it in GitHub Desktop.
reads and lists a directory forwards and backwards by date
my $path = '/home/opuperl';
opendir my($dirh), $path or die "can't opendir $path: $!";
my @flist = sort { -M $a <=> -M $b } # sort by mod time
map { "$path/$_" } # need full paths for sort
grep ! m/^\./ # remove dotfiles
,readdir $dirh;
closedir $dirh;
use Data::Dumper;
print "Newest First\n".Dumper( @flist )."\n\n";
################################################################################
my $path = '/home/opuperl';
opendir my($dirh), $path or die "can't opendir $path: $!";
my @flist = reverse sort { -M $a <=> -M $b } # sort by mod time
map { "$path/$_" } # need full paths for sort
grep ! m/^\./ # remove dotfiles
,readdir $dirh;
closedir $dirh;
use Data::Dumper;
print "Oldest First\n".Dumper( @flist );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment