http://qs321.pair.com?node_id=11124148


in reply to Re^3: A short whishlist of Perl5 improvements leaping to Perl7
in thread A short whishlist of Perl5 improvements leaping to Perl7

Yes, Python doesn't have block scopes.

It has 4 scope levels° - it took me a while to understand them - and function scope is the smallest.

To mimic something similar to blocks you'll need again a named function in Python, since "lambdas" (aka anonymous subs in Perl) are limited to one statement only. Python compensates it by allowing nested named functions, leading to enclosed scope. *

> push @out, {A => $one, b => $two} while my ($one, undef, $two) = some_function())

This is certainly not doing what you expect, those $one and $two variables are different.

DB<17> @out=() DB<18> $x=2; push @out, { A =>$one } while my $one = $x-- DB<19> x @out 0 HASH(0x31f07b8) 'A' => undef 1 HASH(0x31f0410) 'A' => undef DB<20> @out=() DB<21> $x=2; push @out, { A =>$one } while $one = $x-- DB<22> x @out 0 HASH(0x32023b0) 'A' => 2 1 HASH(0x3202428) 'A' => 1 DB<23>

Please keep in mind that declarations are only effective for following statements.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) Local, Global, Built-in, Enclosed

UPDATE

*) remember Py's mantra about "explicit is better than implicit"? Perl's scoping rules are explicit ones here (and easier to understand)