in reply to my Scope Pop Quiz

(c.)
But, contrary to what I would have expected from ike's above, dumping $rv from
perl -d strictscript.pl
tells me that $rv remains undef right up to exit.
Clarification anyone? ysth cites the doc, but that leaves me unclear what the conditions/criteria are that trigger the variant behaviours. Or must we simply accept that undefined behavior cannot ever be predicted?

Update: ikegami and I are both testing against AS on 'doze, but I'm using 5.8.6 build 811 here on (bastardized) w2k.

However, re dave_the_m's below, don't recall (and too lazy to hunt up now) anything in the delta docs that suggested any change in scoping that was obviously relevant here.

dave_the-m's observation "that might change" (understood as: "future vers may not behave the same way") summarizes my previous understanding of "undefined behavior" but the diff between ike's results and mine, on systems with no-known-relevant delta suggests something more akin to "random behaviour."

Replies are listed 'Best First'.
Re^2: my Scope Pop Quiz
by dave_the_m (Monsignor) on Apr 08, 2005 at 20:49 UTC
    Or must we simply accept that undefined behavior cannot ever be predicted
    That's the whole point of undefined behaviour :-)

    As it happens there's a difference between the compile-time and run-time scope of $rv; at compile time its scoped to EOF so the print sees the same lexical; at run-time its scoped to the loop, so gets set to undef at the end of the loop. But that might change.

    Stuff where the loop may not get executed, such as my $rv if $false gets more complicated.

    Dave.

Re^2: my Scope Pop Quiz
by dave_the_m (Monsignor) on Apr 08, 2005 at 21:22 UTC
    There hasn't been a change in scoping between perl versions (AFAIKT); it's always been like that, and it ends up undef on every perl I've tested it on from 5.5003 to 5.9.2. So the behaviour appears to be predictable, but you should't rely on it. For example, saying 'its undefined behaviour' reserves us the right to change its behaviour to something totally random if that makes the internal implementation more efficient.

    Dave.