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