Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: apply a regular expression to glob'd filenames

by 1nickt (Canon)
on Oct 01, 2019 at 20:58 UTC ( [id://11106927]=note: print w/replies, xml ) Need Help??


in reply to apply a regular expression to glob'd filenames

Hi, this is not a job for a regexp. Use the core module File::Basename to handle stripping extensions, or even better use Path::Tiny or Path::Iterator::Rule to find the files and get your desired output.

Here's one way:

$ ls /tmp/11106920/
123456.tif 123_456.tif 666_666.jpeg 678_910.tif
$ perl -Mstrict -MPath::Tiny -wE 'path("/tmp/11106920")->visit( sub { +say $_->basename(".tif") if /[0-9]+_[0-9]+\.tif/ } );'
678_910 123_456

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found