in reply to my versus our in nested regex
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: my versus our in nested regex
by liz (Monsignor) on Oct 18, 2003 at 17:19 UTC | |
Re: Re: my versus our in nested regex
by Anonymous Monk on Oct 18, 2003 at 17:20 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2003 at 17:44 UTC | |
by demerphq (Chancellor) on Oct 18, 2003 at 18:10 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2003 at 18:56 UTC | |
by Aristotle (Chancellor) on Oct 19, 2003 at 00:17 UTC | |
by demerphq (Chancellor) on Oct 18, 2003 at 21:06 UTC | |
| |
by Anonymous Monk on Oct 18, 2003 at 18:36 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2003 at 18:40 UTC |