[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[ID 20000128.003] Bug in magic locals vs block loops?



The attached prints (note "block while" and "block until"):

    it don't with block while
    it works with stmt while
    it don't with block until
    it works with stmt until
    it works with block if
    it works with stmt if

under

    $ perl -v
    This is perl, version 5.005_03 built for i386-linux

I understand that $1 etc are magically local to blocks.  However, the
regexp searches and the references to $1 here are all in the same
block.  Besides, if this were a legitimate block-related difference,
I'd expect the block forms of "while" and "if" to both succeed or both
fail.

Bug or (incomprehensible <wink>) feature?

looks-like-a-bug-to-me-ly y'rs  - tim


$var = "it works or it don't";

$var =~ /(don't)/; # set $1 to "don't"
while ($var !~ /(works)/) {
    die "oops!";    # shouldn't get here ("works" should be found)
}
print "it $1 with block while\n";

$var =~ /(don't)/;
die "oops!" while $var !~ /(works)/;
print "it $1 with stmt while\n";

$var =~ /(don't)/;
until ($var =~ /(works)/) {
    die "oops!";
}
print "it $1 with block until\n";

$var =~ /(don't)/;
die "oops!" until $var =~ /(works)/;
print "it $1 with stmt until\n";

$var =~ /(don't)/;
if ($var !~ /(works)/) {
    die "oops!";
}
print "it $1 with block if\n";

$var =~ /(don't)/;
die "oops!" if $var !~ /(works)/;
print "it $1 with stmt if\n";



Follow-Ups from:
Larry Wall <larry@wall.org>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]