[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000128.003] Bug in magic locals vs block loops?
Tim_Peters@Dragonsys.com writes:
: 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?
Not that Perl doesn't have its share of incomprehensible features, but
I think this one's a bit of buglette too. Especially considering that
it works "right" in Perl 4.
On the other hand, since the buglette is related to the optimization of
not saving and restoring the pattern match context around every loop
iteration, we might be slow to fix it, if we can't figure a decent way
to do it. Fact is that almost nobody ever writes loop conditions with
!~, and the buglette won't show up with =~ because then the pattern
doesn't match on the last iteration, and $1 wouldn't be set anyway.
Plus nowadays there's a bit of a magical lexical scope around entire
while loops and if statements as well. (Not that your buglette is
lexical, it's dynamic.) But anyway, if you write:
$wink = "y'rs\n";
if (my $wink = "wink-ly ") {
print $wink;
}
print "$wink";
You'll find that it prints "wink-ly y'rs", despite the fact that the
my is not within a syntactic block. I suspect that's a feature.
Your buglette is a bit less of a feature, I'd say.
Mind, I'm not promising we won't fix it. I don't make promises like that. :-)
: looks-like-a-bug-to-me-ly y'rs - tim
Nice to hear from you after your long sojourn in snake-strewn lands!
Larry
- Follow-Ups from:
-
Ronald J Kimball <rjk@linguist.dartmouth.edu>
- References to:
-
Tim_Peters@Dragonsys.com
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]