I have two scenarios here, and in the first one, I am not seeing the
logic I would normally expect. I'll compact the code as to save everyone
from scrolling. I have strict and warnings enabled (as I always do). Can
someone tell me why in the first case $1 isn't initialized and in the
second case it is?


# First run(catch $1 and $2, check $2 for correctness (it is), print $1)

my $email = '[EMAIL PROTECTED]';
$email =~ /(.*)@(.*)/;
if ($2 !~ /domain\.com/) {
        print "var 2 is bad\n";
}
print "$1\n";

/** prints 'uninitialized' for line 'print "$1\n";**/


# Second run(same as above, but the if will fail:

my $email = '[EMAIL PROTECTED]';
$email =~ /(.*)@(.*)/;
if ($2 !~ /domain\.com/) {
        print "var 2 is bad\n";
}
print "$1\n";

/** prints
var 2 is bad
steveb
*/

Why does the $1 initialize and print only if the 'if' fails?

TIA,

Steve

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


Reply via email to