Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Writing compact conditional regex's

by furry_marmot (Pilgrim)
on Feb 06, 2011 at 20:29 UTC ( #886549=note: print w/ replies, xml ) Need Help??


in reply to Writing compact conditional regex's

If I understand your first two lines correctly, you're trying to isolate just the filename, without '.avi'. You can use the /b switch, along with /s, to get a bare listing, and then parse out the filename on the fly.

File::Find would also be an excellent choice, but I'm just commenting on the code you have.

The two patterns are almost identical, so just anchor the second one, use a character class ([xe]), and you should be good.

And lastly, you can put most of that into the for loop, and use the regexes on $_ instead of creating temporary variables.

for( map{ s/\\*([^\\]+)\.avi\n/$1/; $_ } `cmd /c dir /s /b *.avi` ) { $inventory{$1} = $2 if /^(.*?)s\d{1,2}[xe]\d{1,2})/i); } # BROKEN OUT -- follow the numbers for( map{ s/\\*([^\\]+)\.avi\n/$1/; # 2: isolate filename between last # backslash (if any) and newli +ne $_ } # 3: pass on $_, not result of s// +/, which is the # number of replacements made `cmd /c dir /s /b *.avi` # 1: get avi files, including sub- +dirs. # dir is a shell (cmd) command +, so # you might need to call it th +is way. ) { $inventory{$1} = $2 if /^(.*?)s\d{1,2}[xe]\d{1,2})/i); }
--marmot


Comment on Re: Writing compact conditional regex's
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-23 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls