Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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


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

In reply to Re^4: A short whishlist of Perl5 improvements leaping to Perl7 by LanX
in thread A short whishlist of Perl5 improvements leaping to Perl7 by rsFalse

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2023-03-28 11:22 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (67 votes). Check out past polls.