Recent Changes - Search:

Softwares

.

PERL

perlcheat - Perl 5 Cheat Sheet

NAME

perlcheat - Perl 5 Cheat Sheet

DESCRIPTION

This 'cheat sheet' is a handy reference, meant for beginning Perl programmers. Not everything is mentioned, but 195 features may already be overwhelming.

The sheet




1.	  CONTEXTS  SIGILS  ref        ARRAYS        HASHES

2.	  void      $scalar SCALAR     @array        %hash

3.	  scalar    @array  ARRAY      @array[0, 2]  @hash{'a', 'b'}

4.	  list      %hash   HASH       $array[0]     $hash{'a'}

5.	            &sub    CODE

6.	            *glob   GLOB       SCALAR VALUES

7.	                    FORMAT     number, string, ref, glob, undef

8.	  REFERENCES

9.	  \      reference       $$foo[1]       aka $foo->[1]
10.	  $@%&*  dereference     $$foo{bar}     aka $foo->{bar}
11.	  []     anon. arrayref  ${$$foo[1]}[2] aka $foo->[1]->[2]
12.	  {}     anon. hashref   ${$$foo[1]}[2] aka $foo->[1][2]
13.	  \()    list of refs

14.	                         NUMBERS vs STRINGS    LINKS

15.	  OPERATOR PRECEDENCE    =          =          perldoc.perl.org
16.	  ->                     +          .           search.cpan.org
17.	  ++ --                  == !=      eq ne              cpan.org
18.	  **                     < > <= >=  lt gt le ge          pm.org
19.	  ! ~ \ u+ u-            <=>        cmp                p3rl.org
20.	  =~ !~                                           perlmonks.org
21.	  * / % x                SYNTAX
22.	    + - .                  foreach (LIST) { }     for (a;b;c) { }
23.	    << >>                  while   (e) { }        until (e)   { }
24.	    named uops             if      (e) { } elsif (e) { } else { }
25.	    < > <= >= lt gt le ge  unless  (e) { } elsif (e) { } else { }
26.	    == != <=> eq ne cmp ~~ given   (e) { when (e) {} default {} }
27.	    &
28.	    | ^             REGEX METACHARS          REGEX MODIFIERS
29.	    &&              ^      string begin      /i case insensitive
30.	  || //           $      str end (bfr \n)  /m line based ^$
31.	    .. ...          +      one or more       /s . includes \n
32.	  ?:              *      zero or more      /x ignore wh.space
33.	  = += -= *= etc  ?      zero or one       /p preserve
34.	  , =>            {3,7}  repeat in range   /a ASCII    /aa safe
35.	  list ops        |      alternation       /l locale   /d  dual
36.	  not             []     character class   /u Unicode
37.	  and             \b     word boundary     /e evaluate /ee rpts
38.	  or xor          \z     string end        /g global
39.	                  ()     capture           /o compile pat once
40.	  DEBUG           (?:p)  no capture
41.	      -MO=Deparse    (?#t)  comment           REGEX CHARCLASSES
42.	   -MO=Terse      (?=p)  ZW pos ahead      .   [^\n]
43.	      -D##           (?!p)  ZW neg ahead      \s  whitespace
44.	      -d:Trace       (?<=p) ZW pos behind \K  \w  word chars
45.	                                    (?<!p) ZW neg behind     \d  digits
46.	    CONFIGURATION   (?>p)  no backtrack      \pP named property
47.	    perl -V:ivsize  (?|p|p)branch reset      \h  horiz.wh.space
48.	                  (?&NM) cap to name       \R  linebreak
49.	                                                                                      \S \W \D \H negate
50.	    FUNCTION RETURN LISTS
51.	    stat      localtime    caller         SPECIAL VARIABLES
52.	      0 dev    0 second      0 package     $_    default variable
53.	      1 ino    1 minute      1 filename    $0    program name
54.	      2 mode   2 hour        2 line        $/    input separator
55.	      3 nlink  3 day         3 subroutine  $\    output separator
56.	      4 uid    4 month-1     4 hasargs     $|    autoflush
57.	      5 gid    5 year-1900   5 wantarray   $!    sys/libcall error
58.	      6 rdev   6 weekday     6 evaltext    $@    eval error
59.	      7 size   7 yearday     7 is_require  $$    process ID
60.	      8 atime  8 is_dst      8 hints       $.    line number
61.	      9 mtime                9 bitmask     @ARGV command line args
62.	    10 ctime               10 hinthash    @INC  include paths
63.	    11 blksz               3..10 only     @_    subroutine args
64.	    12 blcks               with EXPR      %ENV  environment


ACKNOWLEDGEMENTS

The first version of this document appeared on Perl Monks, where several people had useful suggestions. Thank you, Perl Monks.

A special thanks to Damian Conway, who didn't only suggest important changes, but also took the time to count the number of listed features and make a Perl 6 version to show that Perl will stay Perl.

AUTHOR

Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks.

SEE ALSO • http://perlmonks.org/?node_id=216602 - the original PM post

http://perlmonks.org/?node_id=238031 - Damian Conway's Perl 6 version

http://juerd.nl/site.plp/perlcheat - home of the Perl Cheat Sheet


Edit - History - Print - Recent Changes - Search
Page last modified on November 30, 2012, at 02:22 AM