On Wed, 12 Jan 2005 17:27:46 -0700, Dan Fish <[EMAIL PROTECTED]> wrote:
> Are ALL pattern matching variables set back to undef once another m// or
> s/// expression is encountered, even if it contains no parenthized
> expressions?
> 
> For example, I would have expected $1 & $2 to be valid in BOTH print
> statements below...

       The numbered match variables ($1, $2, $3, etc.) and the related punctu-
       ation set ($+, $&, $`, $', and $^N) are all dynamically scoped until
       the end of the enclosing block or _until the next successful match_,
       whichever comes first. 

Thus:
__Successfull second pattern match__
perl -e '$foo = "hello"; $foo =~ /(l+)/; print "$1\n"; print "ok\n" if
$foo =~ /hello/; print " $1\n"'
ll
ok 

__Unsuccessfull second pattern match__
perl -e '$foo = "hello"; $foo =~ /(l+)/; print "$1\n"; print "nope\n"
unless $foo =~ /helo/; print " $1\n"'
ll
nope 
ll


Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to