This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add qr/\b{gcb}/
[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
72a86618
MB
26 SYNTAX
27 OPERATOR PRECEDENCE foreach (LIST) { } for (a;b;c) { }
28 -> while (e) { } until (e) { }
29 ++ -- if (e) { } elsif (e) { } else { }
30 ** unless (e) { } elsif (e) { } else { }
31 ! ~ \ u+ u- given (e) { when (e) {} default {} }
32 =~ !~
33 * / % x NUMBERS vs STRINGS FALSE vs TRUE
34 + - . = = undef, "", 0, "0"
35 << >> + . anything else
36 named uops == != eq ne
37 < > <= >= lt gt le ge < > <= >= lt gt le ge
38 == != <=> eq ne cmp ~~ <=> cmp
8fd8d6f4 39 &
72a86618
MB
40 | ^ REGEX MODIFIERS REGEX METACHARS
41 && /i case insensitive ^ string begin
42 || // /m line based ^$ $ str end (bfr \n)
43 .. ... /s . includes \n + one or more
44 ?: /x ignore wh.space * zero or more
2ba1f20a 45 = += last goto /p preserve ? zero or one
72a86618
MB
46 , => /a ASCII /aa safe {3,7} repeat in range
47 list ops /l locale /d dual | alternation
48 not /u Unicode [] character class
64935bc6 49 and /e evaluate /ee rpts \b boundary
72a86618
MB
50 or xor /g global \z string end
51 /o compile pat once () capture
52 DEBUG (?:p) no capture
53 -MO=Deparse REGEX CHARCLASSES (?#t) comment
54 -MO=Terse . [^\n] (?=p) ZW pos ahead
55 -D## \s whitespace (?!p) ZW neg ahead
56 -d:Trace \w word chars (?<=p) ZW pos behind \K
57 \d digits (?<!p) ZW neg behind
58 CONFIGURATION \pP named property (?>p) no backtrack
59 perl -V:ivsize \h horiz.wh.space (?|p|p)branch reset
60 \R linebreak (?<n>p)named capture
61 \S \W \D \H negate \g{n} ref to named cap
62 \K keep left part
8fd8d6f4
J
63 FUNCTION RETURN LISTS
64 stat localtime caller SPECIAL VARIABLES
891dc8cf
MB
65 0 dev 0 second 0 package $_ default variable
66 1 ino 1 minute 1 filename $0 program name
67 2 mode 2 hour 2 line $/ input separator
68 3 nlink 3 day 3 subroutine $\ output separator
69 4 uid 4 month-1 4 hasargs $| autoflush
70 5 gid 5 year-1900 5 wantarray $! sys/libcall error
71 6 rdev 6 weekday 6 evaltext $@ eval error
72 7 size 7 yearday 7 is_require $$ process ID
73 8 atime 8 is_dst 8 hints $. line number
74 9 mtime 9 bitmask @ARGV command line args
75 10 ctime 10 hinthash @INC include paths
76 11 blksz 3..10 only @_ subroutine args
77 12 blcks with EXPR %ENV environment
8fd8d6f4
J
78
79=head1 ACKNOWLEDGEMENTS
80
81The first version of this document appeared on Perl Monks, where several
82people had useful suggestions. Thank you, Perl Monks.
83
84A special thanks to Damian Conway, who didn't only suggest important changes,
85but also took the time to count the number of listed features and make a
86Perl 6 version to show that Perl will stay Perl.
87
88=head1 AUTHOR
89
740d4bb2 90Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks.
8fd8d6f4
J
91
92=head1 SEE ALSO
93
4a8d6f4f
MS
94=over 4
95
96=item *
97
98L<http://perlmonks.org/?node_id=216602> - the original PM post
99
100=item *
101
102L<http://perlmonks.org/?node_id=238031> - Damian Conway's Perl 6 version
103
104=item *
105
106L<http://juerd.nl/site.plp/perlcheat> - home of the Perl Cheat Sheet
107
108=back