Just another Perl shrine | |
PerlMonks |
Re: Evolution of pythonby stevieb (Canon) |
on Jul 07, 2019 at 15:58 UTC ( [id://11102505]=note: print w/replies, xml ) | Need Help?? |
Instead of braces, Python uses specific indenting instead. It provides the exact same functionality as Perl's scoping braces: Python:
Perl:
In the latter (Perl) example, I could left-justify all of the code, and it would work the same. Essentially, the indentation is for ease of reading. In Python, the indentation is mandatory. Get one indent spacing incorrect, and your program will either fail, or will cause weird issues, possibly in far-away code. One of the most basic problems Python newbies have is incorrect indenting. Sometimes Python will warn about it, but not always. However, in Perl, if you miss a closing brace, the process will fail, explaining what went wrong. "I wondered whether Perl programmers would simply instead specify an array, as named, to a particular scope as specified by parenthesis." If I'm understanding the question, yes, that's extremely common. It's called a lexical variable. If it's declared within a block, it is not accessible to any other part of the program (unless a reference is returned to it, but I digress).
In Section
Seekers of Perl Wisdom
|
|