| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "PERLCHEAT 1" |
| 58 |
.TH PERLCHEAT 1 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
perlcheat \- Perl 5 Cheat Sheet |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
This 'cheat sheet' is a handy reference, meant for beginning Perl |
| 68 |
programmers. Not everything is mentioned, but 195 features may |
| 69 |
already be overwhelming. |
| 70 |
.SS "The sheet" |
| 71 |
.IX Subsection "The sheet" |
| 72 |
.Vb 10 |
| 73 |
\& CONTEXTS SIGILS ref ARRAYS HASHES |
| 74 |
\& void $scalar SCALAR @array %hash |
| 75 |
\& scalar @array ARRAY @array[0, 2] @hash{\*(Aqa\*(Aq, \*(Aqb\*(Aq} |
| 76 |
\& list %hash HASH $array[0] $hash{\*(Aqa\*(Aq} |
| 77 |
\& &sub CODE |
| 78 |
\& *glob GLOB SCALAR VALUES |
| 79 |
\& FORMAT number, string, ref, glob, undef |
| 80 |
\& REFERENCES |
| 81 |
\& \e reference $$foo[1] aka $foo\->[1] |
| 82 |
\& $@%&* dereference $$foo{bar} aka $foo\->{bar} |
| 83 |
\& [] anon. arrayref ${$$foo[1]}[2] aka $foo\->[1]\->[2] |
| 84 |
\& {} anon. hashref ${$$foo[1]}[2] aka $foo\->[1][2] |
| 85 |
\& \e() list of refs |
| 86 |
\& SYNTAX |
| 87 |
\& OPERATOR PRECEDENCE foreach (LIST) { } for (a;b;c) { } |
| 88 |
\& \-> while (e) { } until (e) { } |
| 89 |
\& ++ \-\- if (e) { } elsif (e) { } else { } |
| 90 |
\& ** unless (e) { } elsif (e) { } else { } |
| 91 |
\& ! ~ \e u+ u\- given (e) { when (e) {} default {} } |
| 92 |
\& =~ !~ |
| 93 |
\& * / % x NUMBERS vs STRINGS FALSE vs TRUE |
| 94 |
\& + \- . = = undef, "", 0, "0" |
| 95 |
\& << >> + . anything else |
| 96 |
\& named uops == != eq ne |
| 97 |
\& < > <= >= lt gt le ge < > <= >= lt gt le ge |
| 98 |
\& == != <=> eq ne cmp ~~ <=> cmp |
| 99 |
\& & |
| 100 |
\& | ^ REGEX MODIFIERS REGEX METACHARS |
| 101 |
\& && /i case insensitive ^ string begin |
| 102 |
\& || // /m line based ^$ $ str end (bfr \en) |
| 103 |
\& .. ... /s . includes \en + one or more |
| 104 |
\& ?: /x /xx ign. wh.space * zero or more |
| 105 |
\& = += last goto /p preserve ? zero or one |
| 106 |
\& , => /a ASCII /aa safe {3,7} repeat in range |
| 107 |
\& list ops /l locale /d dual | alternation |
| 108 |
\& not /u Unicode [] character class |
| 109 |
\& and /e evaluate /ee rpts \eb boundary |
| 110 |
\& or xor /g global \ez string end |
| 111 |
\& /o compile pat once () capture |
| 112 |
\& DEBUG (?:p) no capture |
| 113 |
\& \-MO=Deparse REGEX CHARCLASSES (?#t) comment |
| 114 |
\& \-MO=Terse . [^\en] (?=p) ZW pos ahead |
| 115 |
\& \-D## \es whitespace (?!p) ZW neg ahead |
| 116 |
\& \-d:Trace \ew word chars (?<=p) ZW pos behind \eK |
| 117 |
\& \ed digits (?<!p) ZW neg behind |
| 118 |
\& CONFIGURATION \epP named property (?>p) no backtrack |
| 119 |
\& perl \-V:ivsize \eh horiz.wh.space (?|p|p)branch reset |
| 120 |
\& \eR linebreak (?<n>p)named capture |
| 121 |
\& \eS \eW \eD \eH negate \eg{n} ref to named cap |
| 122 |
\& \eK keep left part |
| 123 |
\& FUNCTION RETURN LISTS |
| 124 |
\& stat localtime caller SPECIAL VARIABLES |
| 125 |
\& 0 dev 0 second 0 package $_ default variable |
| 126 |
\& 1 ino 1 minute 1 filename $0 program name |
| 127 |
\& 2 mode 2 hour 2 line $/ input separator |
| 128 |
\& 3 nlink 3 day 3 subroutine $\e output separator |
| 129 |
\& 4 uid 4 month\-1 4 hasargs $| autoflush |
| 130 |
\& 5 gid 5 year\-1900 5 wantarray $! sys/libcall error |
| 131 |
\& 6 rdev 6 weekday 6 evaltext $@ eval error |
| 132 |
\& 7 size 7 yearday 7 is_require $$ process ID |
| 133 |
\& 8 atime 8 is_dst 8 hints $. line number |
| 134 |
\& 9 mtime 9 bitmask @ARGV command line args |
| 135 |
\& 10 ctime 10 hinthash @INC include paths |
| 136 |
\& 11 blksz 3..10 only @_ subroutine args |
| 137 |
\& 12 blcks with EXPR %ENV environment |
| 138 |
.Ve |
| 139 |
.SH ACKNOWLEDGEMENTS |
| 140 |
.IX Header "ACKNOWLEDGEMENTS" |
| 141 |
The first version of this document appeared on Perl Monks, where several |
| 142 |
people had useful suggestions. Thank you, Perl Monks. |
| 143 |
.PP |
| 144 |
A special thanks to Damian Conway, who didn't only suggest important changes, |
| 145 |
but also took the time to count the number of listed features and make a |
| 146 |
Raku version to show that Perl will stay Perl. |
| 147 |
.SH AUTHOR |
| 148 |
.IX Header "AUTHOR" |
| 149 |
Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks. |
| 150 |
.SH "SEE ALSO" |
| 151 |
.IX Header "SEE ALSO" |
| 152 |
.IP \(bu 4 |
| 153 |
<https://perlmonks.org/?node_id=216602> \- the original PM post |
| 154 |
.IP \(bu 4 |
| 155 |
<https://perlmonks.org/?node_id=238031> \- Damian Conway's Raku version |
| 156 |
.IP \(bu 4 |
| 157 |
<https://juerd.nl/site.plp/perlcheat> \- home of the Perl Cheat Sheet |