Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Perl cheat sheet On-the-go

by Aragorn (Curate)
on Jun 26, 2004 at 11:59 UTC ( #369811=sourcecode: print w/ replies, xml ) Need Help??

Category: Miscellaneous
Author/Contact Info
Description: Juerd Waalboer's Perl 5 Cheat Sheet as an iPod Note.
<a name="top">Perl 5 Cheat Sheet</a>
by Arjen Laarhoven, based on Juerd Waalboer's cheat sheet

<a name="conttoc"><a href="#cont">Contexts</a></a>
<a name="sigtoc"><a href="#sig">Sigils</a></a>
<a name="arrtoc"><a href="#arr">Arrays</a></a>
<a name="hashtoc"><a href="#hash">Hashes</a></a>
<a name="scaltoc"><a href="#scal">Scalar values</a></a>
<a name="reftoc"><a href="#ref">References</a></a>
<a name="prectoc"><a href="#prec">Operator precedence</a></a>
<a name="numstrtoc"><a href="#numstr">Numbers/Strings</a></a>
<a name="remetatoc"><a href="#remeta">Regex metacharacters</a></a>
<a name="remodtoc"><a href="#remod">Regex modifiers</a></a>
<a name="rechartoc"><a href="#rechar">Regex character classes</a></a>
<a name="funcrettoc"><a href="#funcret">Function return lists</a></a>
<a name="specvartoc"><a href="#specvars">Special variables</a></a>
<a name="dotoc"><a href="#do">Do</a></a>
<a name="donttoc"><a href="#dont">Don't</a></a>
<a name="linkstoc"><a href="#links">Links</a></a>

<a name="cont"><a href="#conttoc">CONTEXTS</a></a>
  void scalar list

<a name="sig"><a href="#sigtoc">SIGILS</a></a>
  $scalar @array %hash
  &sub *glob

<a name="arr"><a href="#arrtoc">ARRAYS</a></a>
  @array @array[0, 2]
  $array[0]

<a name="hash"><a href="#hashtoc">HASHES</a></a>
  %hash $hash{'a'}
  @hash{'a','b'}

<a name="scal"><a href="#scaltoc">SCALAR VALUES</a></a>
  number string reference
  glob undef

<a name="ref"><a href="#reftoc">REFERENCES</a></a>
  \ reference
  $@%&* dereference
  [] anon arrayref
  {} anon hashref
  \() list of refs

  $$foo[1] => $foo->[1]
  $$foo{bar} => $foo->{bar}
  ${$$foo[1]}[2]
    => $foo->[1]->[2]
  ${$$foo[1]}[2]
    => $foo->[1][2]

<a name="prec"><a href="#prectoc">Operator Precedence</a></a>
  ->
  ++ --
  **
  ! ~ / u+ u-
  =~ !~
  * / % x
  + - .
  << >>
  named uops
  < > <= >= lt gt le ge
  == != <=> eq ne cmp
  &
  | ^
  &&
  ||
  .. ...
  ?:
  = += -= *= etc.
  list ops
  not
  and
  or
  xor

<a name="numstr"><a href="#numstrtoc">NUMBERS/STRINGS</a></a>
  NUM           STR
  =                 =
  +                 .
  == !=          eq ne
  < > <= >=    lt gt le ge
  <=>             cmp

<a name="remeta"><a href="#remetatoc">REGEX METACHARACTERS</a></a>
  ^ string begin
  $ string end
  + one or more
  * zero or more
  ? zero or one
  {3,7} repeat in range
  () capture
  (?:) no capture
  [] character class
  | alternation
  \b word boundary
  \z string end

<a name="remod"><a href="#remodtoc">REGEX MODIFIERS</a></a>
  /i case insens.
  /m line based ^$
  /s . includes \n
  /x ignore whitespace
  /g global

<a name="rechar"><a href="#rechartoc">REGEX CHARCLASSES</a></a>
  .     == [^\n]
  \s   == [\x20\f\t\r\n]
  \w == [A-Za-z0-9_]
  \d  == [0-9]
  \S, \W and \D negate

<a name="funcret"><a href="#funcrettoc">FUNCTION RETURN LISTS</a></a>
  stat         localtime
  0 dev      0 second
  1 ino       1 minute
  2 mode   2 hour
  3 nlink     3 day
  4 uid        4 mon-1
  5 gid        5 yr-1900
  6 rdev     6 wday
  7 size      7 yrday
  8 atime   8 is_dst
  9 mtime
 10 ctime
 11 blksz
 12 blcks

  caller
  0 package     5 wantarray  
  1 filename    6 evaltext
  2 line             7 is_require
  3 subroutine 8 hints
  4 hashargs   9 bitmask 
  0..9 only with EXPR

<a name="specvars"><a href="#specvarstoc">SPECIAL VARIABLES</a></a>
  $_ default variable
  $0 program name
  $/ input separator
  $\ output separator
  $| autoflush
  $! sys/libcall error
  $@ eval error
  $$ process ID
  $. line number
  @ARGV command line args
  @INC include paths
  @_ subroutine args
  %ENV environment

<a name="do"><a href="#dotoc">DO</a></a>
  use strict;
  use warnings;
  my $var;
  open() or die $!;
  use Modules;

<a name="dont"><a href="#donttoc">DON'T</a></a>
  "$foo"
  $$variable_name
  `$userinput`
  /$userinput/ 

<a name="links"><a href="#linkstoc">LINKS</a></a>
  perl.plover.com
  search.cpan.org
  cpan.org
  pm.org
  tpj.com
  perldoc.com
  perl.com
  perlmonks.org
  use.perl.org
  perl.apache.org
  parrotcode.org

Comment on Perl cheat sheet On-the-go
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://369811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2015-07-31 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls