0% found this document useful (0 votes)
80 views

Perl 5 Cheat Sheet: Contexts Sigils Arrays Hashes Do

This cheat sheet summarizes key concepts in Perl including data types (scalars, arrays, hashes), references, regular expressions, functions, and special variables. It provides an overview of common Perl syntax like for/foreach loops, if/else statements, and modules. Key Perl data types include scalars for individual values, arrays for ordered lists, and hashes for key-value pairs. References allow scalars, arrays and hashes to reference other variables. Regular expressions provide pattern matching with metacharacters and modifiers. Special variables like $_ provide default values or information about the script execution.

Uploaded by

ja_moses
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Perl 5 Cheat Sheet: Contexts Sigils Arrays Hashes Do

This cheat sheet summarizes key concepts in Perl including data types (scalars, arrays, hashes), references, regular expressions, functions, and special variables. It provides an overview of common Perl syntax like for/foreach loops, if/else statements, and modules. Key Perl data types include scalars for individual values, arrays for ordered lists, and hashes for key-value pairs. References allow scalars, arrays and hashes to reference other variables. Regular expressions provide pattern matching with metacharacters and modifiers. Special variables like $_ provide default values or information about the script execution.

Uploaded by

ja_moses
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Perl 5 Cheat Sheet

CONTEXTS SIGILS ARRAYS HASHES DO


void $scalar whole: @array %hash use strict;
scalar @array slice: @array[0, 2] @hash{'a', 'b'} use warnings;
list %hash element: $array[0] $hash{'a'} my $var;
&sub open() or die $!;
*glob SCALAR VALUES use Modules;
number, string, reference, glob, undef
REFERENCES DON'T
\ references $$foo[1] aka $foo->[1] "$foo"
$@%&* dereference $$foo{bar} aka $foo->{bar} $$variable_name
[] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2] `$userinput`
{} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2] /$userinput/
\() list of refs
NUMBERS vs STRINGS LINKS
OPERATOR PRECEDENCE = = perl.com
-> + . perlmonks.org
++ -- == != eq ne use.perl.org
** < > <= >= lt gt le ge perl.apache.org
! ~ \ u+ u- <=> cmp parrotcode.org
=~ !~ perl.plover.com
*/%x SYNTAX search.cpan.org
+-. for (LIST) { }, for (a;b;c) { } cpan.org
<< >> while ( ) { }, until ( ) { } pm.org
named uops if ( ) { } elsif ( ) { } else { } tpj.com
< > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { } perldoc.com
== != <=> eq ne cmp for equals foreach (ALWAYS)
&
|^ REGEX METACHARS REGEX MODIFIERS
&& ^ string begin /i case insens.
|| $ str. end (before \n) /m line based ^$
.. ... + one or more /s . includes \n
?: * zero or more /x ign. wh.space
= += -= *= etc. ? zero or one /g global
, => {3,7} repeat in range
list ops () capture REGEX CHARCLASSES
not (?:) no capture . == [^\n]
and [] character class \s == [\x20\f\t\r\n]
or xor | alternation \w == [A-Za-z0-9_]
\b word boundary \d == [0-9]
\z string end \S, \W and \D negate

FUNCTION RETURN LISTS


stat localtime caller SPECIAL VARIABLES
0 dev 0 second 0 package $_ default variable From Last Matched Pattern:
1 ino 1 minute 1 filename $0 program name $1..$9 subpatterns
2 mode 2 hour 2 line $% current page num $& string matched
3 nlink 3 day 3 subroutine $= current page len $` string preceeding
4 uid 4 month-1 4 hasargs $| autoflush $' string following
5 gid 5 year-1900 5 wantarray $! sys/libcall error
6 rdev 6 weekday 6 evaltext $@ eval error For the Print command:
7 size 7 yearday 7 is_require $$ process ID $, output field separator
8 atime 8 is_dst 8 hints $. line number $" interpolated array sep.
9 mtime 9 bitmask @ARGV command line args $# numeric output format
10 ctime just use @INC include paths $\ output rec separator
11 blksz POSIX:: 3..9 only @_ subroutine args $/ input rec separator
12 blcks strftime! with EXPR %ENV environment

You might also like