in reply to Re: Re: Regular Expression Question
in thread What happens with empty $1 in regular expressions? (was: Regular Expression Question)
The proper way to protect yourself from using unintended old values in $1 and friends is to program defensively and check if a pattern match succeeded before trying to use captured subexpressions (as previous messages in this thread have shown).Well, that's a way. Another way is to stylistically outlaw all uses of $1 et seq, except in the right side of a substitution. Any other "capturing" should be done as list-context assignment:
Then it's very clear what the scope and origination of $first and $second are.my ($first, $second) = $source =~ /blah(this)blah(that)blah/;
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Regular Expression Question
by danger (Priest) on Feb 28, 2001 at 23:29 UTC |