The Perl Cheat Sheet - Programming Languages | CS 4700, Study notes of Programming Languages

Material Type: Notes; Class: Programming Languages; Subject: Computer Science; University: Utah State University; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-4hp
koofers-user-4hp ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The Perl Cheat sheet
CONTEXTS SIGILS ARRAYS HASHES
void $scalar whole: @array %hash
scalar @array slice: @array[0, 2] @hash{โ€™aโ€™, โ€™bโ€™}
list %hash element: $array[0] $hash{โ€™aโ€™}
&sub
*glob SCALAR VALUES
number, string, reference, glob, undef
REFERENCES
\ references $$foo[1] aka $foo->[1]
$@%&* dereference $$foo{bar} aka $foo->{bar}
[] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
{} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
\() list of refs
NUMBERS vs STRINGS
OPERATOR PRECEDENCE = =
-> + .
++ -- == != eq ne
** < > <= >= lt gt le ge
! ~ \ u+ u- <=> cmp
=~ !~
* / % x SYNTAX
+ - . for (LIST) { }, for (a;b;c) { }
<< >> while ( ) { }, until ( ) { }
named uops if ( ) { } elsif ( ) { } else { }
< > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { }
== != <=> 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
SPECIAL VARIABLES
$_ 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
pf3

Partial preview of the text

Download The Perl Cheat Sheet - Programming Languages | CS 4700 and more Study notes Programming Languages in PDF only on Docsity!

The Perl Cheat sheet

CONTEXTS SIGILS ARRAYS HASHES

void $scalar whole: @array %hash scalar @array slice: @array[0, 2] @hash{โ€™aโ€™, โ€™bโ€™} list %hash element: $array[0] $hash{โ€™aโ€™} &sub glob SCALAR VALUES number, string, reference, glob, undef REFERENCES \ references $$foo[1] aka $foo->[1] $@%& dereference $$foo{bar} aka $foo->{bar} [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2] {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2] () list of refs NUMBERS vs STRINGS OPERATOR PRECEDENCE = = -> +. ++ -- == != eq ne ** < > <= >= lt gt le ge ! ~ \ u+ u- <=> cmp =~ !~

  • / % x SYNTAX
  • -. for (LIST) { }, for (a;b;c) { } << >> while ( ) { }, until ( ) { } named uops if ( ) { } elsif ( ) { } else { } < > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { } == != <=> 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 SPECIAL VARIABLES $_ 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