1N/A=head1 NAME
1N/A
1N/Aperlcheat - Perl 5 Cheat Sheet
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AThis 'cheat sheet' is a handy reference, meant for beginning Perl
1N/Aprogrammers. Not everything is mentioned, but 194 features may
1N/Aalready be overwhelming.
1N/A
1N/A=head2 The sheet
1N/A
1N/A CONTEXTS SIGILS ARRAYS HASHES
1N/A void $scalar whole: @array %hash
1N/A scalar @array slice: @array[0, 2] @hash{'a', 'b'}
1N/A list %hash element: $array[0] $hash{'a'}
1N/A &sub
1N/A *glob SCALAR VALUES
1N/A number, string, reference, glob, undef
1N/A REFERENCES
1N/A \ references $$foo[1] aka $foo->[1]
1N/A $@%&* dereference $$foo{bar} aka $foo->{bar}
1N/A [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
1N/A {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
1N/A \() list of refs
1N/A NUMBERS vs STRINGS LINKS
1N/A OPERATOR PRECEDENCE = = perl.plover.com
1N/A -> + . search.cpan.org
1N/A ++ -- == != eq ne cpan.org
1N/A ** < > <= >= lt gt le ge pm.org
1N/A ! ~ \ u+ u- <=> cmp tpj.com
1N/A =~ !~ perldoc.com
1N/A * / % x SYNTAX
1N/A + - . for (LIST) { }, for (a;b;c) { }
1N/A << >> while ( ) { }, until ( ) { }
1N/A named uops if ( ) { } elsif ( ) { } else { }
1N/A < > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { }
1N/A == != <=> eq ne cmp for equals foreach (ALWAYS)
1N/A &
1N/A | ^ REGEX METACHARS REGEX MODIFIERS
1N/A && ^ string begin /i case insens.
1N/A || $ str. end (before \n) /m line based ^$
1N/A .. ... + one or more /s . includes \n
1N/A ?: * zero or more /x ign. wh.space
1N/A = += -= *= etc. ? zero or one /g global
1N/A , => {3,7} repeat in range
1N/A list ops () capture REGEX CHARCLASSES
1N/A not (?:) no capture . == [^\n]
1N/A and [] character class \s == [\x20\f\t\r\n]
1N/A or xor | alternation \w == [A-Za-z0-9_]
1N/A \b word boundary \d == [0-9]
1N/A \z string end \S, \W and \D negate
1N/A DO
1N/A use strict; DON'T LINKS
1N/A use warnings; "$foo" perl.com
1N/A my $var; $$variable_name perlmonks.org
1N/A open() or die $!; `$userinput` use.perl.org
1N/A use Modules; /$userinput/ perl.apache.org
1N/A parrotcode.org
1N/A FUNCTION RETURN LISTS
1N/A stat localtime caller SPECIAL VARIABLES
1N/A 0 dev 0 second 0 package $_ default variable
1N/A 1 ino 1 minute 1 filename $0 program name
1N/A 2 mode 2 hour 2 line $/ input separator
1N/A 3 nlink 3 day 3 subroutine $\ output separator
1N/A 4 uid 4 month-1 4 hasargs $| autoflush
1N/A 5 gid 5 year-1900 5 wantarray $! sys/libcall error
1N/A 6 rdev 6 weekday 6 evaltext $@ eval error
1N/A 7 size 7 yearday 7 is_require $$ process ID
1N/A 8 atime 8 is_dst 8 hints $. line number
1N/A 9 mtime 9 bitmask @ARGV command line args
1N/A 10 ctime just use @INC include paths
1N/A 11 blksz POSIX:: 3..9 only @_ subroutine args
1N/A 12 blcks strftime! with EXPR %ENV environment
1N/A
1N/A=head1 ACKNOWLEDGEMENTS
1N/A
1N/AThe first version of this document appeared on Perl Monks, where several
1N/Apeople had useful suggestions. Thank you, Perl Monks.
1N/A
1N/AA special thanks to Damian Conway, who didn't only suggest important changes,
1N/Abut also took the time to count the number of listed features and make a
1N/APerl 6 version to show that Perl will stay Perl.
1N/A
1N/A=head1 AUTHOR
1N/A
1N/AJuerd Waalboer <juerd@cpan.org>, with the help of many Perl Monks.
1N/A
1N/A=head1 SEE ALSO
1N/A
1N/A http://perlmonks.org/?node_id=216602 the original PM post
1N/A http://perlmonks.org/?node_id=238031 Damian Conway's Perl 6 version
1N/A http://juerd.nl/site.plp/perlcheat home of the Perl Cheat Sheet