<?xml version="1.0" encoding="windows-1252"?>
<node id="216602" title="Perl cheat sheet" created="2002-11-29 16:54:09" updated="2005-08-15 11:13:14">
<type id="121">
perlcraft</type>
<author id="132236">
Juerd</author>
<data>
<field name="doctext">
Perl 5 cheat sheet v6 by Juerd Waalboer, http://juerd.nl/
.
 CONTEXTS  SIGILS   ARRAYS        HASHES
 void      $scalar  @array        %hash
 scalar    @array   @array[0, 2]  @hash{'a', 'b'}
 list      %hash    $array[0]     $hash{'a'}
           &amp;sub
           *glob    SCALAR VALUES
                    number, string, reference, glob, undef
 REFERENCES
 \     references      $$foo[1]       aka $foo-&gt;[1]
 $@%&amp;* dereference     $$foo{bar}     aka $foo-&gt;{bar}
 []    anon. arrayref  ${$$foo[1]}[2] aka $foo-&gt;[1]-&gt;[2]
 {}    anon. hashref   ${$$foo[1]}[2] aka $foo-&gt;[1][2]
 \()   list of refs
                         NUMBERS vs STRINGS  LINKS
 OPERATOR PRECEDENCE     =          =        perl.plover.com
 -&gt;                      +          .        search.cpan.org
 ++ --                   == !=      eq ne         cpan.org
 **                      &lt; &gt; &lt;= &gt;=  lt gt le ge   pm.org
 ! ~ \ u+ u-             &lt;=&gt;        cmp           tpj.com
 =~ !~                                            perldoc.com
 * / % x                 SYNTAX
 + - .                   for    (LIST) { }, for (a;b;c) { }
 &lt;&lt; &gt;&gt;                   while  ( ) { }, until ( ) { }
 named uops              if     ( ) { } elsif ( ) { } else { }
 &lt; &gt; &lt;= &gt;= lt gt le ge   unless ( ) { } elsif ( ) { } else { }
 == != &lt;=&gt; eq ne cmp     for equals foreach (ALWAYS)
 &amp;
 | ^              REGEX METACHARS          REGEX MODIFIERS
 &amp;&amp;               ^ string begin           /i case insensitive
 ||               $ string end (before \n) /m line based ^$
 .. ...           + one or more            /s dot includes \n
 ?:               * any amount             /x ignore wh.space
 = += -= *= etc.  ? zero or one            /g global
 , =&gt;             () capture
 list ops         (?:) no capture     REGEX CHARCLASSES
 not              [] character class  .  == [^\n]
 and              | alternation       \s == [\x20\f\t\r\n]
 or xor           {1,2} amount        \w == [A-Za-z0-9_]
                  \b word boundary    \d == [0-9]
                  \z string end       \S, \W and \D negate
 ALWAYS
 use strict;        NEVER unless pro      LINKS
 use warnings;      "$foo"                perl.com
 my $var;           $foo = "bar"; $$foo   perlmonks.org
 open() or die $!;  `$userinput`          use.perl.org
 use Modules;       /$userinput/          perl.apache.org


This is my christmas gift for all Perl newbies out there :)
Have fun!

v1: initial version
v2: fixed per merlyn's suggestions
v3: added missing dollar signs
v4: changed per TheDamian's suggestions
v5: changed per TheDamian's suggestions


Note: It's hard to maintain two copies, so if you want
the most recent version, visit my homepage. Sorry!

Update: If you have Perl 5.8.1 or later installed, try this
on a command line:

perldoc perlcheat  # :)</field>
</data>
</node>
