Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886549]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-04-29 09:56 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.