Grep a file by date in Perl

Hi,
I have a path "/usr/home/Test/Files" which contains a bunch of .txt files. The name format of these files are :

/usr/home/Test/Files:

test_20111003_hdl.txt.  
test_20111002_hdl.txt
test_20111001_hdl.txt
test_20110930_hdl.txt..

I want to grep the latest file by the date concatenated in the name of the file.  Can any one pls let me know how.

Thanks,
new_perl_userAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
use POSIX;
$todaysfilename=strftime"/usr/home/Test/Files/test_%Y%m%d_hdl.txt",localtime;
0
parparovCommented:
You need the latest file, or the files past a certain date?
0
new_perl_userAuthor Commented:
it should grep latest file.
0
parparovCommented:
latest file would be:
my $todaysfile = pop sort (grep /test_.*_hdl.txt$/, readdir DIR);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
for the file that was modified most recently, regardless of the name:

($latestfile)=(sort map{sprintf"%9x\0%s",(stat)[9]*10,$_}</usr/home/Test/Files/*.txt>)[-1]=~/\0(.*)/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.