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

In reply to Re: Writing compact conditional regex's by furry_marmot
in thread Writing compact conditional regex's by Mad_Mac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.