Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Finding a file by age (Newest First)

by sacked (Hermit)
on Jun 04, 2004 at 17:40 UTC ( [id://361009]=note: print w/replies, xml ) Need Help??


in reply to Finding a file by age (Newest First)

#!/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";
This example uses the Orcish Maneuver to cache the results of the file test operator -M.

--sacked

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://361009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-25 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found