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