1PERLCHEAT(1) Perl Programmers Reference Guide PERLCHEAT(1)
2
3
4
6 perlcheat - Perl 5 Cheat Sheet
7
9 This 'cheat sheet' is a handy reference, meant for beginning Perl
10 programmers. Not everything is mentioned, but 195 features may already
11 be overwhelming.
12
13 The sheet
14 CONTEXTS SIGILS ARRAYS HASHES
15 void $scalar whole: @array %hash
16 scalar @array slice: @array[0, 2] @hash{'a', 'b'}
17 list %hash element: $array[0] $hash{'a'}
18 &sub
19 *glob SCALAR VALUES
20 number, string, reference, glob, undef
21 REFERENCES
22 \ references $$foo[1] aka $foo->[1]
23 $@%&* dereference $$foo{bar} aka $foo->{bar}
24 [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
25 {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
26 \() list of refs
27 NUMBERS vs STRINGS LINKS
28 OPERATOR PRECEDENCE = = perl.plover.com
29 -> + . search.cpan.org
30 ++ -- == != eq ne cpan.org
31 ** < > <= >= lt gt le ge pm.org
32 ! ~ \ u+ u- <=> cmp tpj.com
33 =~ !~ perldoc.com
34 * / % x SYNTAX
35 + - . for (LIST) { }, for (a;b;c) { }
36 << >> while ( ) { }, until ( ) { }
37 named uops if ( ) { } elsif ( ) { } else { }
38 < > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { }
39 == != <=> eq ne cmp ~~ for equals foreach (ALWAYS)
40 &
41 | ^ REGEX METACHARS REGEX MODIFIERS
42 && ^ string begin /i case insens.
43 || // $ str. end (before \n) /m line based ^$
44 .. ... + one or more /s . includes \n
45 ?: * zero or more /x ign. wh.space
46 = += -= *= etc. ? zero or one /g global
47 , => {3,7} repeat in range /o cmpl pat. once
48 list ops () capture
49 not (?:) no capture REGEX CHARCLASSES
50 and [] character class . == [^\n]
51 or xor | alternation \s == whitespace
52 \b word boundary \w == word characters
53 \z string end \d == digits
54 DO \S, \W and \D negate
55 use strict; DON'T
56 use warnings; "$foo" LINKS
57 my $var; $$variable_name perl.com
58 open() or die $!; `$userinput` use.perl.org
59 use Modules; /$userinput/ perl.apache.org
60
61 FUNCTION RETURN LISTS
62 stat localtime caller SPECIAL VARIABLES
63 0 dev 0 second 0 package $_ default variable
64 1 ino 1 minute 1 filename $0 program name
65 2 mode 2 hour 2 line $/ input separator
66 3 nlink 3 day 3 subroutine $\ output separator
67 4 uid 4 month-1 4 hasargs $| autoflush
68 5 gid 5 year-1900 5 wantarray $! sys/libcall error
69 6 rdev 6 weekday 6 evaltext $@ eval error
70 7 size 7 yearday 7 is_require $$ process ID
71 8 atime 8 is_dst 8 hints $. line number
72 9 mtime 9 bitmask @ARGV command line args
73 10 ctime just use @INC include paths
74 11 blksz POSIX:: 3..9 only @_ subroutine args
75 12 blcks strftime! with EXPR %ENV environment
76
78 The first version of this document appeared on Perl Monks, where
79 several people had useful suggestions. Thank you, Perl Monks.
80
81 A special thanks to Damian Conway, who didn't only suggest important
82 changes, but also took the time to count the number of listed features
83 and make a Perl 6 version to show that Perl will stay Perl.
84
86 Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks.
87
89 http://perlmonks.org/?node_id=216602 the original PM post
90 http://perlmonks.org/?node_id=238031 Damian Conway's Perl 6 version
91 http://juerd.nl/site.plp/perlcheat home of the Perl Cheat Sheet
92
93
94
95perl v5.12.4 2011-06-07 PERLCHEAT(1)