Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

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 +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

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (8)
    As of 2014-12-28 19:31 GMT
    Find Nodes?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?

      Results (182 votes), past polls