go ahead... be a heretic | |
PerlMonks |
Re: non-greedy piecewise matchingby ikegami (Patriarch) |
on Aug 02, 2007 at 17:40 UTC ( [id://630349]=note: print w/replies, xml ) | Need Help?? |
The greediness is just your first problem. Problem #2: You're using the g modifier in list context, causing all the matches to be returned at once. You'll never print anything other than the first file name.
Problem #3: If there's anything after the last .xml, you have yourself an infinite loop. Checking if pos is less then length is a bad idea when using the c modifier. Fix:
Finally: Using the c modifier is rather useless, ugly if you only have one regexp, and it's rather complex (as shown by the number of errors). Fix:
Tip: If you really did have a use for c (e.g. if you were writting a lexer), then you'd have multiple regexps, and aliasing $_ to the variable containing the text would be worthwhile.
In Section
Seekers of Perl Wisdom
|
|