John W. Krahn wrote:
Mumia W. wrote:
That happens because the match variables ($1, $2, ...) are only changed
when a regular expression matches; otherwise, they are left alone.
In the first case, "$2 !~ /domain\.com/" succeeds but does not capture
anything, so the numbered match variables are unset.
Your situation reinforces the rule that you should always test if the
match succeeded before you attempt to use the match variables:
my $email = '[EMAIL PROTECTED]';
my @f = (undef, $email =~ /(.*)\@(.*)/);
Why did you put undef in there? It serves no useful purpose other than making
the code harder to understand for beginners.
my @f = $email =~ /(.*)\@(.*)/;
Presumably so that $f[1] eq $1 and $f[2] eq $2?
But I agree: unnecessary and confusing.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/