This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update PerlCheat to 5.14
[perl5.git] / pod / perlcheat.pod
CommitLineData
8fd8d6f4
J
1=head1 NAME
2
3perlcheat - Perl 5 Cheat Sheet
4
5=head1 DESCRIPTION
6
7This 'cheat sheet' is a handy reference, meant for beginning Perl
b3631f69 8programmers. Not everything is mentioned, but 195 features may
8fd8d6f4
J
9already be overwhelming.
10
11=head2 The sheet
12
891dc8cf
MB
13 CONTEXTS SIGILS ref ARRAYS HASHES
14 void $scalar SCALAR @array %hash
15 scalar @array ARRAY @array[0, 2] @hash{'a', 'b'}
16 list %hash HASH $array[0] $hash{'a'}
17 &sub CODE
18 *glob GLOB SCALAR VALUES
19 FORMAT number, string, ref, glob, undef
8fd8d6f4 20 REFERENCES
891dc8cf
MB
21 \ reference $$foo[1] aka $foo->[1]
22 $@%&* dereference $$foo{bar} aka $foo->{bar}
23 [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
24 {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
25 \() list of refs
26 NUMBERS vs STRINGS LINKS
27 OPERATOR PRECEDENCE = = perldoc.perl.org
28 -> + . search.cpan.org
29 ++ -- == != eq ne cpan.org
30 ** < > <= >= lt gt le ge pm.org
31 ! ~ \ u+ u- <=> cmp p3rl.org
32 =~ !~ perlmonks.org
33 * / % x SYNTAX
34 + - . foreach (LIST) { } for (a;b;c) { }
35 << >> while (e) { } until (e) { }
36 named uops if (e) { } elsif (e) { } else { }
37 < > <= >= lt gt le ge unless (e) { } elsif (e) { } else { }
38 == != <=> eq ne cmp ~~ given (e) { when (e) {} default {} }
8fd8d6f4 39 &
891dc8cf
MB
40 | ^ REGEX METACHARS REGEX MODIFIERS
41 && ^ string begin /i case insensitive
42 || // $ str end (bfr \n) /m line based ^$
43 .. ... + one or more /s . includes \n
44 ?: * zero or more /x ignore wh.space
45 = += -= *= etc ? zero or one /p preserve
46 , => {3,7} repeat in range /a ASCII /aa safe
47 list ops | alternation /l locale /d dual
48 not [] character class /u Unicode
49 and \b word boundary /e evaluate /ee rpts
50 or xor \z string end /g global
51 () capture /o compile pat once
52 DEBUG (?:p) no capture
53 -MO=Deparse (?#t) comment REGEX CHARCLASSES
54 -MO=Terse (?=p) ZW pos ahead . [^\n]
55 -D## (?!p) ZW neg ahead \s whitespace
56 -d:Trace (?<=p) ZW pos behind \K \w word chars
57 (?<!p) ZW neg behind \d digits
58 CONFIGURATION (?>p) no backtrack \pP named property
59 perl -V:ivsize (?|p|p)branch reset \h horiz.wh.space
60 (?&NM) cap to name \R linebreak
61 \S \W \D \H negate
8fd8d6f4
J
62 FUNCTION RETURN LISTS
63 stat localtime caller SPECIAL VARIABLES
891dc8cf
MB
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 10 hinthash @INC include paths
75 11 blksz 3..10 only @_ subroutine args
76 12 blcks with EXPR %ENV environment
8fd8d6f4
J
77
78=head1 ACKNOWLEDGEMENTS
79
80The first version of this document appeared on Perl Monks, where several
81people had useful suggestions. Thank you, Perl Monks.
82
83A special thanks to Damian Conway, who didn't only suggest important changes,
84but also took the time to count the number of listed features and make a
85Perl 6 version to show that Perl will stay Perl.
86
87=head1 AUTHOR
88
740d4bb2 89Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks.
8fd8d6f4
J
90
91=head1 SEE ALSO
92
4a8d6f4f
MS
93=over 4
94
95=item *
96
97L<http://perlmonks.org/?node_id=216602> - the original PM post
98
99=item *
100
101L<http://perlmonks.org/?node_id=238031> - Damian Conway's Perl 6 version
102
103=item *
104
105L<http://juerd.nl/site.plp/perlcheat> - home of the Perl Cheat Sheet
106
107=back