{"id":1040,"date":"2011-01-03T22:05:40","date_gmt":"2011-01-03T22:05:40","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1040"},"modified":"2011-01-03T22:07:00","modified_gmt":"2011-01-03T22:07:00","slug":"perl-5-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2011\/01\/perl-5-cheat-sheet\/","title":{"rendered":"Perl 5 cheat sheet"},"content":{"rendered":"<p>This &#8216;cheat sheet&#8217; is a handy reference, meant for beginning Perl programmers. Not everything is mentioned, but 195 features may already be overwhelming.<\/p>\n<pre>Perl 5 cheat sheet v8\r\n\r\n CONTEXTS  SIGILS             ARRAYS        HASHES\r\n void      $scalar   whole:   @array        %hash\r\n scalar    @array    slice:   @array[0, 2]  @hash{'a', 'b'}\r\n list      %hash     element: $array[0]     $hash{'a'}\r\n           &amp;sub\r\n           *glob    SCALAR VALUES\r\n                    number, string, reference, glob, undef\r\n REFERENCES\r\n \\     references      $$foo[1]       aka $foo-&gt;[1]\r\n $@%&amp;* dereference     $$foo{bar}     aka $foo-&gt;{bar}\r\n []    anon. arrayref  ${$$foo[1]}[2] aka $foo-&gt;[1]-&gt;[2]\r\n {}    anon. hashref   ${$$foo[1]}[2] aka $foo-&gt;[1][2]\r\n \\()   list of refs\r\n                         NUMBERS vs STRINGS  LINKS\r\n OPERATOR PRECEDENCE     =          =        perl.plover.com\r\n -&gt;                      +          .        search.cpan.org\r\n ++ --                   == !=      eq ne         cpan.org\r\n **                      &lt; &gt; &lt;= &gt;=  lt gt le ge   pm.org\r\n ! ~ \\ u+ u-             &lt;=&gt;        cmp           tpj.com\r\n =~ !~                                            perldoc.com\r\n * \/ % x                 SYNTAX\r\n + - .                   for    (LIST) { }, for (a;b;c) { }\r\n &lt;&lt; &gt;&gt;                   while  ( ) { }, until ( ) { }\r\n named uops              if     ( ) { } elsif ( ) { } else { }\r\n &lt; &gt; &lt;= &gt;= lt gt le ge   unless ( ) { } elsif ( ) { } else { }\r\n == != &lt;=&gt; eq ne cmp     for equals foreach (ALWAYS)\r\n &amp;\r\n\r\n | ^              REGEX METACHARS            REGEX MODIFIERS\r\n &amp;&amp;               ^     string begin         \/i case insens.\r\n ||               $     str. end (before \\n) \/m line based ^$\r\n .. ...           +     one or more          \/s . includes \\n\r\n ?:               *     zero or more         \/x ign. wh.space\r\n = += -= *= etc.  ?     zero or one          \/g global\r\n , =&gt;             {3,7} repeat in range\r\n list ops         ()    capture          REGEX CHARCLASSES\r\n not              (?:)  no capture       .  == [^\\n]\r\n and              []    character class  \\s == [\\x20\\f\\t\\r\\n]\r\n or xor           |     alternation      \\w == [A-Za-z0-9_]\r\n                  \\b    word boundary    \\d == [0-9] \r\n                  \\z    string end       \\S, \\W and \\D negate\r\n DO\r\n use strict;        DON'T            LINKS\r\n use warnings;      \"$foo\"           perl.com       \r\n my $var;           $$variable_name  perlmonks.org  \r\n open() or die $!;  `$userinput`     use.perl.org   \r\n use Modules;       \/$userinput\/     perl.apache.org\r\n                                     parrotcode.org \r\n FUNCTION RETURN LISTS\r\n stat      localtime    caller         SPECIAL VARIABLES\r\n  0 dev    0 second     0 package      $_    default variable\r\n  1 ino    1 minute     1 filename     $0    program name\r\n  2 mode   2 hour       2 line         $\/    input separator\r\n  3 nlink  3 day        3 subroutine   $\\    output separator\r\n  4 uid    4 month-1    4 hasargs      $|    autoflush\r\n  5 gid    5 year-1900  5 wantarray    $!    sys\/libcall error\r\n  6 rdev   6 weekday    6 evaltext     $@    eval error\r\n  7 size   7 yearday    7 is_require   $$    process ID\r\n  8 atime  8 is_dst     8 hints        $.    line number\r\n  9 mtime               9 bitmask      @ARGV command line args\r\n 10 ctime  just use                    @INC  include paths\r\n 11 blksz  POSIX::      3..9 only      @_    subroutine args\r\n 12 blcks  strftime!    with EXPR      %ENV  environment\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This &#8216;cheat sheet&#8217; is a handy reference, meant for beginning Perl programmers. Not everything is mentioned, but 195 features may already be overwhelming. Perl 5 cheat sheet v8 CONTEXTS SIGILS ARRAYS HASHES void $scalar whole: @array %hash scalar @array slice: @array[0, 2] @hash{&#8216;a&#8217;, &#8216;b&#8217;} list %hash element: $array[0] $hash{&#8216;a&#8217;} &amp;sub *glob SCALAR VALUES number, string, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1040","post","type-post","status-publish","format-standard","hentry","category-perl-mamp"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1040"}],"version-history":[{"count":2,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1040\/revisions"}],"predecessor-version":[{"id":1042,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1040\/revisions\/1042"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}