Difference between revisions of "Python-Perl cheatsheet"
Devicerandom (Talk | contribs) |
Devicerandom (Talk | contribs) |
||
Line 49: | Line 49: | ||
|($fred, $barney, $dino) = ("flintstone", "rubble", undef); | |($fred, $barney, $dino) = ("flintstone", "rubble", undef); | ||
| | | | ||
+ | | | ||
+ | |- | ||
+ | | array concatenation | ||
+ | | a+b | ||
+ | | (@a, @b) | ||
+ | |you can also mix like {@a, 3, @b, undef) | ||
+ | |||
|} | |} | ||
[[Category:Programming]] | [[Category:Programming]] |
Revision as of 12:58, 25 April 2011
what | Python | Perl | notes | |
---|---|---|---|---|
null type | None | undef | not exactly identical | |
String concatenation | "py"+"thon" | "pe"."rl" | ||
declare a list | [1,2,3] | (1,2,3) | ||
array length | len(array) | $#array + 1 | Python returns the length of array. Perl gives me the index of the last element. | |
range(1,100) | (1..100) | |||
create a list from whitespaced values | (no real equivalent) | qw( fred barney wilma dino) | You can use separators others than parenthesis, e.g. qw ! fred barney wilma dino ! | |
multiple assignment | fred, barney, dino = "flintstone", "rubble", None | ($fred, $barney, $dino) = ("flintstone", "rubble", undef); | ||
array concatenation | a+b | (@a, @b) | you can also mix like {@a, 3, @b, undef) |