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/05 04:34] 47.82.15.134 old revision restored (2013/09/22 14:25) |
notes:perl_cheat_sheet [2026/06/07 22:32] (current) 114.119.135.37 old revision restored (2013/09/15 02:44) |
||
|---|---|---|---|
| Line 14: | Line 14: | ||
| * Parenthesis are optional unless part of syntax. | * Parenthesis are optional unless part of syntax. | ||
| * '' | * '' | ||
| - | * '' | ||
| ===== Numbers ===== | ===== Numbers ===== | ||
| Line 62: | Line 61: | ||
| * 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> | ||
| - | * '' | ||
| ===== Control Structures ===== | ===== Control Structures ===== | ||
| Line 101: | Line 90: | ||
| * ''<>'' | * ''<>'' | ||
| chomp; | chomp; | ||
| - | print LOGFILE | + | print "It was $_ that I saw!\n"; |
| }</ | }</ | ||
| * '' | * '' | ||
| print sort <>; | print sort <>; | ||
| - | * C-like printf function %g for number auto-format, | + | * 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 ===== | ||