Python Traps
Perl and Python are both dynamic languages that share some common ancestors and appeared within five years of each other (1987 and 1991). Perl 4 even stole Python’s object system for Perl 5. Although the two languages are more alike than their superficial syntax would suggest, they also see many of the same things from different perspectives.
Python and Perl sometimes use different words for the same concepts, and sometimes they use the same words for different concepts; see Table 21-1.
Table 21-1. A mapping of Python to Perl jargon
Python Perl Tuple List List Array Dictionary Hash Variables begin with
$,@, or%in Perl. Using sigils like$strlets Perl keep its nouns and its verbs separate, so you never have to worry about accidentally overwriting some important built-in the way you do in Python if you usestrfor your purposes. You can override built-ins in Perl, but never accidentally the way you can in Python.Don’t forget to
use warningsso Perl notices things that in Python give you exceptions. Otherwise in Perl you only learn about these things if you test for them, so if you forget, you never know. See alsowarningsandautodiein Chapter 27.Many built-in functions take default arguments or have default behavior for their most common cases. See Chapter 27.
Python’s methods take explicit parameter lists. In Perl, you unpack the arguments to your function, which gives you great flexibility in the number and order of the arguments your function takes. We consider this a feature, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access