Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Find the last item in a series of files

by CountZero (Bishop)
on Jun 16, 2017 at 16:30 UTC ( #1192963=note: print w/replies, xml ) Need Help??


in reply to Re: Find the last item in a series of files
in thread Find the last item in a series of files

Very nice solution!

A small improvement makes the regex a bit more specific and have it reject filenames that do not match the expected file name template.

use strict; use warnings; my %names; /^([^.]+)\.(\d{3})$/ and $names{$1}[$2] = $_ while <DATA>; print $names{$_}[-1] for sort keys %names; __DATA__ file.001 file.003 not.good.001 file.002 file.10 one.004 two.001 two.003 two.five one.002 one.001 one.0039 two.002 .005

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2020-09-29 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (145 votes). Check out past polls.

    Notices?