FAQ

Am Fr 27. Mai 2016, 04:19:32, aristotle schrieb:
* l.mai@web.de via RT [2016-02-05 12:00]:
Am Do 04. Feb 2016, 23:29:24, hmbrand schrieb:
Normally, the part inside the parens scopes to the block connected,
so this does not surprise me.
The difference is that

for (A; B; C) { D }

should be equivalent to

A; while (B) { D } continue { C }

C is executed after A, B, and D. That's why it's surprising that the
loop body D can see and access variables declared in C, even though
their definitions haven't even been executed yet.
Variables declared in the A part of for(A;B;C) do not remain declared
past the loop. If you are serious about strict textual equivalence of
these constructs then that must also bother you. Does it?
I'm not serious about strict equivalence, let alone textual.

What bothers me is the time traveling / backwards scoping of C, which comes last in execution order.

Anyway, the equivalence wrt A can be easily restored by wrapping the whole thing in another scope:

   do { A; while (B) { D } continue { C } };

It's a bit harder to make 'my $x' not return undef in normal Perl code.

---
via perlbug: queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=127463

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
groupperl5-porters @
categoriesperl
postedMay 27, '16 at 11:18a
activeMay 30, '16 at 8:28p
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2017 Grokbase