0: Perl 5 cheat sheet v6 by Juerd Waalboer, http://juerd.nl/
1: .
2: CONTEXTS SIGILS ARRAYS HASHES
3: void $scalar @array %hash
4: scalar @array @array[0, 2] @hash{'a', 'b'}
5: list %hash $array[0] $hash{'a'}
6: &sub
7: *glob SCALAR VALUES
8: number, string, reference, glob, undef
9: REFERENCES
10: \ references $$foo[1] aka $foo->[1]
11: $@%&* dereference $$foo{bar} aka $foo->{bar}
12: [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
13: {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
14: \() list of refs
15: NUMBERS vs STRINGS LINKS
16: OPERATOR PRECEDENCE = = perl.plover.com
17: -> + . search.cpan.org
18: ++ -- == != eq ne cpan.org
19: ** < > <= >= lt gt le ge pm.org
20: ! ~ \ u+ u- <=> cmp tpj.com
21: =~ !~ perldoc.com
22: * / % x SYNTAX
23: + - . for (LIST) { }, for (a;b;c) { }
24: << >> while ( ) { }, until ( ) { }
25: named uops if ( ) { } elsif ( ) { } else { }
26: < > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { }
27: == != <=> eq ne cmp for equals foreach (ALWAYS)
28: &
29: | ^ REGEX METACHARS REGEX MODIFIERS
30: && ^ string begin /i case insensitive
31: || $ string end (before \n) /m line based ^$
32: .. ... + one or more /s dot includes \n
33: ?: * any amount /x ignore wh.space
34: = += -= *= etc. ? zero or one /g global
35: , => () capture
36: list ops (?:) no capture REGEX CHARCLASSES
37: not [] character class . == [^\n]
38: and | alternation \s == [\x20\f\t\r\n]
39: or xor {1,2} amount \w == [A-Za-z0-9_]
40: \b word boundary \d == [0-9]
41: \z string end \S, \W and \D negate
42: ALWAYS
43: use strict; NEVER unless pro LINKS
44: use warnings; "$foo" perl.com
45: my $var; $foo = "bar"; $$foo perlmonks.org
46: open() or die $!; `$userinput` use.perl.org
47: use Modules; /$userinput/ perl.apache.org
48:
49:
50: This is my christmas gift for all Perl newbies out there :)
51: Have fun!
52:
53: v1: initial version
54: v2: fixed per merlyn's suggestions
55: v3: added missing dollar signs
56: v4: changed per TheDamian's suggestions
57: v5: changed per TheDamian's suggestions
58:
59:
60: Note: It's hard to maintain two copies, so if you want
61: the most recent version, visit my homepage. Sorry!
62:
63: Update: If you have Perl 5.8.1 or later installed, try this
64: on a command line:
65:
66: perldoc perlcheat # :)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|