in reply to Finding a file by age (Newest First)
This example uses the Orcish Maneuver to cache the results of the file test operator -M.#!/usr/bin/perl -w + use strict; my( $mask, $position )= @ARGV; die "Usage:\n\t$0 MASK POSITION\n" unless $mask and $position and $position =~ /^\d+$/ and $position > +0; + opendir( DIR, "." ) or die "can't opendir '.' for read: $!"; my @files= do { my %h; sort { ($h{$b} ||= -M $b) <=> ($h{$a} ||= -M $a) } grep { /^$mask/o } readdir(DIR) }; closedir( DIR ) or warn "error closing dir '.': $!"; + print "Your file is: ", ($files[$position-1] || "not found"), "\n";
|
|---|