This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
notes:perl_cheat_sheet [2026/09/15 05:45] 163.7.15.111 old revision restored (2013/08/31 23:24) |
notes:perl_cheat_sheet [2026/09/16 14:25] (current) 216.73.216.94 old revision restored (2026/09/15 14:12) |
||
|---|---|---|---|
| Line 14: | Line 14: | ||
| * Parenthesis are optional unless part of syntax. | * Parenthesis are optional unless part of syntax. | ||
| + | ===== Numbers ===== | ||
| + | |||
| + | * All numbers are stored in the same format e.g.-6.5e24, | ||
| + | * Underscores for readability are ignored e.g. 0x1377_0B77 | ||
| + | * Arithmetic operators are * / + - % (modulus) %%**%% (exponentiation) | ||
| + | * Comparison operators are < <= == >= > != | ||
| + | |||
| + | ===== Strings ===== | ||
| + | |||
| + | * To use unicode in source code - "use utf8;" | ||
| + | * Single-quoted literals ' | ||
| + | * Double-quoted strings can contain control-characters starting with a backslash and are variable interpolated e/g/ " | ||
| + | * . is for concatenation, | ||
| + | * To insert a character by code - chr(0x05d0). To convert a character to its code - ord(' | ||
| + | * String comparison operators are lt, le, eq, ge, gt, and ne | ||
| ===== Scalar Variables ===== | ===== Scalar Variables ===== | ||
| Line 41: | Line 56: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | ===== Numbers ===== | + | |
| - | + | * Expressions parsed in either a scalar context or a list context. Scalars | |
| - | | + | * List functions may return different scalars |
| - | * Underscores for readability are ignored e.g. 0x1377_0B77 | + | |
| - | * Arithmetic operators | + | |
| - | * Comparison operators are < <= == >= > != | + | |
| - | + | ||
| - | ===== Strings ===== | + | |
| - | * To use unicode | + | |
| - | * Single-quoted literals | + | |
| - | * Double-quoted strings can contain control-characters starting with a backslash and are variable interpolated | + | |
| - | * . is for concatenation, | + | |
| - | * To insert a character by code - chr(0x05d0). To convert a character to its code - ord(' | + | |
| - | * String comparison operators are lt, le, eq, ge, gt, and ne | + | |
| ===== Control Structures ===== | ===== Control Structures ===== | ||
| Line 70: | Line 74: | ||
| }</ | }</ | ||
| * foreach loop <code perl> | * foreach loop <code perl> | ||
| - | # modifications to $rock modify the list element | + | # modifications to $rock modify the list element |
| + | # $_ is used if loop variable is omitted | ||
| }</ | }</ | ||
| Line 77: | Line 82: | ||
| * Read a line of input - '' | * Read a line of input - '' | ||
| * '' | * '' | ||
| + | * Assigning < | ||
| + | |||
| + | ===== User Subroutines ===== | ||
| + | * Subroutines are in their own namespace and are typically called using ''& | ||
| + | * Subroutines can be defined anywhere e.g. <code perl> sub mysub { | ||
| + | my($m, $n) = @_ | ||
| + | $m + $n; | ||
| + | } </ | ||
| + | * The value of the last expression evaluated is returned. | ||
| + | * Arguments are in the list @_ . If ''& | ||
| + | * Lexical scoped variables can be used in any block by prefixing with '' | ||