my variables don't come into existance until the end of the statement in which they are declared, which means that when the regex is being compiled, <update> the lexical scalar,<update> $regex doesn't yet exist.
Using our bypasses this problem.
If you want to avoid using a global, then pre-declare the lexical.
use strict; my $regex; $regex = qr /( # Start capture \( # Start with '(', (?: # Followed by (?>[^()]+) # Non-parenthesis |(??{ $regex }) # Or a balanced () block )* # zero or more times \) # Close capture )/x; # Ending with ')' my $text = '(outer(inner(most inner)))'; $text =~ /$regex/gs; print "$1\n"; __END__ P:\test>junk2 (outer(inner(most inner)))
Updated description in the light of liz's observation below.
In reply to Re: my versus our in nested regex
by BrowserUk
in thread my versus our in nested regex
by Len
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |