I'm was trying use File::Finder to find a filename that is the X oldest file that matches a starting string. (I failed miserably...)
So I abandoned that and am trying anything that might work...
Here's an example:
from the directory listing;
test0
test1
test2
test3
test4
where the files were created in chronological order.

If I pass the parameters "te" and "2" it would return test1.

I'm running perl v5.6.0 built for aix.

This is the code I came up with so far. It will create a list based on the regex for the name and find the Xth file based on position in the list. I need that list to be in chronological order.

#! /usr/bin/perl -w $mask = $ARGV[0]; $position = $ARGV[1]; opendir(DIR,"."); my @files = grep { $_ ne '.' && $_ ne '..' }readdir DIR; closedir(DIR); foreach(@files) { if ($_ =~ m/^$mask/ig) { push(@result,$_) } } print "Your file is: ".$result[$position-1]."\n";
=====================(( U P D A T E ))=====================
Thanks to everyone for there input. I implemented Zaxo's
code and it does exactly what I need.

Thanks for the quick results.

In reply to Finding a file by age (Newest First) by ChuckularOne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.