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
In reply to Re: Re: Re: Regular Expression Question
by merlyn
in thread What happens with empty $1 in regular expressions? (was: Regular Expression Question)
by marcblecher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |