PYTHON VARIABLES
Python is entirely object-based, this means that many Perl programmers will have to get used to working with a combination of objects, compatible operators, and the class-specific methods which can be used to manipulate them.
For example, consider the Perl code fragment below which creates an array and then sorts the results into a new array:
my @array = qw/fred bob alice/; my @sorted = sort @array;
Within Python we can create the new list (the Python array type) and then use the sort() method on the new object to create an ordered version.
array = ['fred','bob','alice'] array.sort()
Although the process still takes two lines, we've created only one list and haven't had to exchange any data with an additional function, everything ...
Get Perl To Python Migration now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.