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