The = sign in python doesn't change the value of the LHS (well, at least as long as you don't consider object attributes) but binds or rebinds the name, so that would be more like glob operations in perl. So b = a might be interpreted as *b = *a. Then all references to @a or $a (python lists act like arrayrefs otherwise, so working with scalars might be closer) will lose the connection, meaning the assignment won't have any effect on any other structure in the code. In perl, with @a = (0,) x $n; or $a = [ (0,) x $n ];, you might have a reference to @a or $a somewhere. So I'd say python's a = [0] * n is perl's *a = \[ (@{ [0] }) x $n ];

Python variables don't act like either perl package variables or lexicals though, but rather like you had a global symbols table, and a an additionnal symbols table lexically bound to each function (so all variables in a function are visible everywhere in that function) that could hide some of the symbols of the global table.


In reply to Re: [OT] Python to Perl. by Eily
in thread [OT] Python to Perl. by BrowserUk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.