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/06/12 11:45] 114.119.152.46 old revision restored (2026/05/24 07:47) |
notes:perl_cheat_sheet [2026/06/13 20:45] (current) 37.122.190.32 old revision restored (2026/05/23 12:38) |
||
|---|---|---|---|
| Line 13: | Line 13: | ||
| * Comments start with # (no block comments) | * Comments start with # (no block comments) | ||
| * Parenthesis are optional unless part of syntax. | * Parenthesis are optional unless part of syntax. | ||
| - | * '' | ||
| - | * '' | ||
| ===== Numbers ===== | ===== Numbers ===== | ||
| Line 61: | Line 59: | ||
| * Expressions parsed in either a scalar context or a list context. Scalars are promoted to single-element lists in list context. | * Expressions parsed in either a scalar context or a list context. Scalars are promoted to single-element lists in list context. | ||
| * List functions may return different scalars - array variables return number of elements. The '' | * List functions may return different scalars - array variables return number of elements. The '' | ||
| - | |||
| - | ===== Hashes ===== | ||
| - | |||
| - | * A hash is a list indexed by a string (key) - a collection of key-value pairs. '' | ||
| - | * Uses scalable, efficient algorithms. Used to be called associative arrays. | ||
| - | * '' | ||
| - | * Assigning a hash to an array unwinds (flattens) it. | ||
| - | * To initialize a hash :<code perl> | ||
| - | %some_hash = ( ' | ||
| - | * When using a big arrow (a fat-comma) or when accessing a value, simple keys don't have to be quoted (barewords) e.g. <code perl> | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * To iterate over hash : <code perl> | ||
| - | print "$key => $value\n"; | ||
| - | print "$key => $hash{$key}\n"; | ||
| - | * %ENV hash holds environment variables. | ||
| ===== Control Structures ===== | ===== Control Structures ===== | ||
| Line 108: | Line 89: | ||
| * ''<>'' | * ''<>'' | ||
| chomp; | chomp; | ||
| - | print LOGFILE | + | print "It was $_ that I saw!\n"; |
| }</ | }</ | ||
| - | * '' | ||
| - | print sort <>; | ||
| - | * C-like printf function %g for number auto-format, | ||
| - | my $format = "The items are: | ||
| - | printf $format, @items; | ||
| - | printf "The items are: | ||
| - | </ | ||
| - | * Filehandles can be barewords (upper-cased) or variables. Special filehandles are : STDIN, STDOUT, STDERR, DATA, ARGV, and ARGVOUT .<code perl> | ||
| - | open BEDROCK, '> | ||
| - | open LOG, '>>: | ||
| - | open my $bedrock, '>: | ||
| - | binmode STDOUT, ': | ||
| - | * '' | ||
| ===== User Subroutines ===== | ===== User Subroutines ===== | ||