blakem has asked for the wisdom of the Perl Monks concerning the following question:
Sometimes while(...) magically deparsed to while(defined(...)), but sometimes it doesn't. How is this decision made?
I looked for documentation on this behaviour but couldn't find any. Flow control keywords aren't listed in perlfunc, do they have their own perldoc page?#### GLOBS cause defined to show up # while(<*.pl>) {} DEFINEDNESS % perl -MO=Deparse -e 'while(<*.pl>) {}' while (defined($_ = CORE::GLOBAL::glob('*.pl', 0))) { (); } # 1 while (<*.pl>) DEFINEDNESS % perl -MO=Deparse -e '1 while(<*.pl>)' '???' while defined($_ = CORE::GLOBAL::glob('*.pl', 0)); #### Simple vars dont # while($x) {} TRUTHFULNESS % perl -MO=Deparse -e 'while($x) {}' while ($x) { (); } # '1 while($x)' TRUTHFULNESS % perl -MO=Deparse -e '1 while($x)' '???' while $x; #### Why do these two behave differently???? # 'while($x = <*.pl>) {} DEFINEDNESS % perl -MO=Deparse -e 'while($x = <*.pl>) {}' while (defined($x = CORE::GLOBAL::glob('*.pl', 0))) { (); } # '1 while($x = <*.pl>) TRUTHFULNESS % perl -MO=Deparse -e '1 while($x = <*.pl>)' '???' while $x = CORE::GLOBAL::glob('*.pl', 0);
-Blake
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: When does while() test for defined vs truth
by wog (Curate) on Dec 17, 2001 at 07:24 UTC | |
by blakem (Monsignor) on Dec 17, 2001 at 07:42 UTC | |
by japhy (Canon) on Dec 17, 2001 at 08:35 UTC | |
by blakem (Monsignor) on Dec 17, 2001 at 08:46 UTC | |
Re: When does while() test for defined vs truth
by raptnor (Initiate) on Dec 17, 2001 at 08:42 UTC | |
It's a bug (was: When does while() test for defined vs truth)
by robin (Chaplain) on Dec 17, 2001 at 20:23 UTC | |
Re: When does while() test for defined vs truth
by impossiblerobot (Deacon) on Dec 17, 2001 at 07:28 UTC |
Back to
Seekers of Perl Wisdom