in reply to Matching Multiple Alternative Patterns and Capturing Multiple Subexpressions

Also, why do I have to declare the variables $pfx and $num outside the while loop for this to work properly?

I think that is because the regular expression code blocks create closures around $pfx and $num when the regex is compiled. This means that the assignments will always be to the $pfx and $num that were declared inside the while loop the first time through. I think doing

local our ($pfx, $num);

inside the while would work but I've not tested it.

I hope this is of use.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Matching Multiple Alternative Patterns and Capturing Multiple Subexpressions
by Jim (Curate) on Sep 09, 2007 at 22:51 UTC
    I tested it. It does work.

    Thanks!

    Jim