> From perldoc perlre: > > The numbered match variables ($1, $2, $3, etc.) and the related > punctuation set ($+, $&, $`, $', and $^N) are all dynamically scoped > until the end of the enclosing block or until the next successful match, > whichever comes first. > > In your first example, $1 is valid until the successful match > /domain\.com/, when > it becomes undefined as there are no capturing parentheses. In the > second example > $1 retains its value since the match fails.
This makes it crystal clear. > > It's always safer to save captured strings before you use them, and I > would never > make a capture variable the target of a regex match as in your $2 !~ > /domain\.com/. I agree...this was a piece of legacy code I am replacing. I ALWAYS name my variables prior to doing any work on them, and as such, I've never used the numbered variables in that manner as to run into such a 'quirk'. RTFM (as quoted) cleared it up for me. > and also, in this case, the test would be better as > > unless ($host eq 'domain.com') { > print "Host name is bad\n"; > } > > unless you really want to test whether the host name /contains/ that > string? Like I said, legacy stuff I'm replacing. > Oh, and I think I also prefer > > my ($name, $host) = split /@/, $email; > > instead of the first regex. Yes, agreed. Thanks so much! Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/