Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Howdy Monks. After many years of being away from the language I'm trying again. This time, I'd like to learn The Right Way. I generally understand this problem (from code I've purloined and beat into shape to suit my own needs) but there are some specifics which confuse me. Now that I know what a backreference is I'd like to better understand (a) how/why to get this match on the files listed below and (b) a more efficient means of matching the extension. Here is the loop (the remainder of comments/questions are in the code):
@files includes (I'd like to match all of these): "__asdf.jpg asdf.jp +g FOO.AVI Hjz-6Nj.JPG this is[myfile].jpg" foreach my $file( @files ) { # I've tried various "character classes (w, W, d, D...), # combinations of anchoring, not anchoring, using + # I'm not getting consistent matches. At best the below # gives me most files but Hjz-6Nj gets "$1 = Hjz" I lose # the hyphen. # # And for $2, when I have a list of extensions like this # is there a sort of array I can place them in? And # what about camel case extensions? This long list seems # really innefficent. if ( $file =~ /(\w+|W).(jpg|JPG|gif|GIF|wmv|WMV|mpg|MPG|avi|AVI)$/ ) + { my $prefix = $1; my $ext = $2; print "prefix: [$prefix]\n"; print "ext: [$ext]\n"; } }

In reply to matching and backreferencing filenames by ezekieldas

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2015-07-05 07:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls