Sunteți pe pagina 1din 2

Perl Quick Reference Card

version 0.02 editor: John Bokma freelance programmer


DRAFT VERSION, check: http://johnbokma.com/perl/
Backslashed Character Escapes !
\n Newline (usually LF) \0 Null character (NUL)
\r Carriage return (usually CR) \033 ESC in octal
\t Horizontal tab (HT) \x7f DEL in hea!eci"al
\f For" #ee! (FF) \cC Control$C
\b %ac&s'ace (%S) \x{263a} Unico!e( )(s"iley)
\a *lert (%EL) \N{NAME} Na"e! character
\e Esca'e (ESC)
Translati"n Escapes !
\u Force net character to u''ercase (+titlecase, in Unico!e)-
\l Force net character to lowercase-
\U Force all #ollowing characters to u''ercase
\L Force all #ollowing characters to lowercase
\Q %ac&slash all #ollowing non$.wor!. characters (/uote"eta)
\E En! \U( \L, or \Q-
Qu"te C"nstructs #
Customary Generic Meaning Interpolates
'' q// Literal string No
.. qq// Literal string 0es
qx// Co""an! eecution 0es
!" q#// 1or! list No
// $// 2attern "atch 0es
%/// %/// 2attern substitution 0es
&/// tr/// Character translation No
'' qr// Regular e'ression 0es
Note3 no inter'olation is !one i# you use single /uotes #or !eli"iters-
Operat"r Precedence $%
Associativiy Arity Precedence Class
None 4 Ter"s( an! list o'erators (le#twar!)
Le#t 5 ()
None 6 ** ((
Right 5 ++
Right 6 , - ) an! unary * an! unary (
Le#t 5 .- ,-
Le#t 5 + / / x
Le#t 5 * ( 0
Le#t 5 11 ))
Right 4(6 Na"e! unary o'erators
None 5 1 ) 1. ). lt 2t le 2e
None 5 .. ,. 1.) eq ne c$3
Le#t 5 4
Le#t 5 5 6
Le#t 5 44
Le#t 5 55
None 5 00 000
Operat"r Precedence &c"ntinued' $%
Associativiy Arity Precedence Class
Right 7 78
Right 5 . *. (. +. an! so on
Le#t 5 , .)
Right 48 List o'erators (rightwar!)
Right 6 n9t
Le#t 5 an:
Le#t 5 9r x9r
File Test Operat"rs ($
(r File is rea!able by e##ecti9e U:D;<:D-
(# File is writable by e##ecti9e U:D;<:D-
(x File is eecutable by e##ecti9e U:D;<:D-
(9 File is owne! by e##ecti9e U:D;<:D-
(; File is rea!able by real U:D;<:D-
(< File is writable by real U:D;<:D-
(= File is eecutable by real U:D;<:D-
(> File is owne! by real U:D;<:D-
(e File eists-
(? File has zero size
(% File has nonzero size (returns size)-
(f File is a 'lain #ile-
(: File is a !irectory-
(l File is a sy"bolic lin&-
(3 File is a na"e! 'i'e (F:F=)-
(@ File is a soc&et-
(b File is a bloc& s'ecial #ile-
(c File is a character s'ecial #ile-
(t Filehan!le is o'en to a tty-
(u File has setui! bit set-
(2 File has setgi! bit set-
(A File has stic&y bit set-
(B File is a tet #ile-
(C File is a binary #ile (o''osite o# $T)-
(M *ge o# #ile (at startu') in (#ractional) !ays since "o!i#ication-
(A *ge o# #ile (at startu') in (#ractional) !ays since last access-
(C *ge o# #ile (at startu') in (#ractional) !ays since ino!e change-
Pattern )"difiers !*%
/D :gnore al'habetic case !istinctions (case insensiti9e)-
/% Let 0 "atch newline an! ignore !e'recate! E+ 9ariable-
/$ Let 6 an! E "atch net e"be!!e! \n-
/x :gnore ("ost) whites'ace an! 'er"it co""ents in 'attern-
/9 Co"'ile 'attern only once-
Additi"nal +,, )"difiers !-.
/2 <lobally #in! all "atches-
/c2 *llow continue! search a#ter #aile! /2 "atch-
Additi"nal s,,, )"difiers !-#
/2 Re'lace globally( that is( all occurences-
/e E9aluate the right si!e as an e'ression-
tr,,, )"difiers !-
/c Co"'le"ent SE*RCHL:ST-
/: Delete #oun! but unre'lace! characters-
/% S/uash !u'licate re'lace! characters-
/eneral Re0e1 )etacharacters !-(
Symbol Atomic Meaning
\> ?aries De$"eta net nonal'hanu"eric character( "eta
net al'hanu"eric character ("aybe)-
>@> No *lternation ("atch one or the other)-
!>" 0es <rou'ing (treat as a unit)-
F>G 0es Character class ("atch one character #ro" a set)-
6 No True at beginning o# string (or a#ter a newline(
"aybe)-
0 0es Aatch one character (ece't newline( nor"ally)-
E No True at en! o# string (or be#ore any newline(
"aybe)-
Re0e1 Quantifiers !-(2!.
Quantifier Atomic Meaning
B No Aatch 4 or "ore ti"es ("ai"al)-
* No Aatch 6 or "ore ti"es ("ai"al)-
7 No Aatch 4 or 6 ti"e ("ai"al)-
{C>UNB} No Aatch eactly COUNT ti"es-
{MHN,} No Aatch at least MIN ti"es ("ai"al)-
{MHN,MA=} No Aatch at least MIN but not "ore than MAX
ti"es ("ai"al)-
BC No Aatch 4 or "ore ti"es ("ini"al)-
8C No Aatch 6 or "ore ti"es ("ini"al)-
CC No Aatch 4 or 6 ti"e ("ini"al)-
{MHN,}7 No Aatch at least MIN ti"es ("ini"al)-
{MHN,MA=}7 No Aatch at least MIN but not "ore than MAX
ti"es ("ini"al)-
E1tended Re0e1 Se3uences !.
Extension Atomic Meaning
(CD>" No Co""ent( !iscar!-
!78>) 0es Cluster$only 'arentheses( no ca'turing-
!7D$%x(D$%x" No Enable;!isable 'attern "o!i#iers-
!7D$%x(D$%x8>) 0es Cluster$only 'arentheses 'lus "o!i#iers-
!7.>) No True i# loo&ahea! assertion succee!s-
!7,>) No True i# loo&ahea! assertion #ails-
!71.>) No True i# loo&behin! assertion succee!s-
!71,>) No True i# loo&behin! assertion #ails-
!7)>) 0es Aatch nonbac&trac&ing sub'attern-
!7{>}" No Eecute e"be!!e! 2erl co!e-
!77{>}" 0es Aatch rege #ro" e"be!!e! 2erl co!e-
!7!>">5>" 0es Aatch with i#$then$else 'attern-
!7!>">" 0es Aatch with i#$then 'attern-
Alphanu+eric Re0e1 )etas4+5"ls !!2!6
Symbol Atomic Meaning
E4 0es Aatch the null character (*SC:: NUL)-
\NNN 0es Aatch the character gi9en in octal( u' to \377-
\n 0es Aatch nth 're9iously ca'ture! string (!eci"al)-
\a 0es Aatch the alar" character (%EL)-
\A No True at the beginning o# a string-
\b 0es Aatch the bac&s'ace character (%S)-
\b No True at a wor! boun!ary-
\C No True when not at a wor! boun!ary-
\c= 0es Aatch the control character Ctrl$F (\cJ)-
\C 0es Aatch one byte (C char) e9en in ut#G (!angerous)-
\: 0es Aatch any !igit character-
\K 0es Aatch any non$!igit character-
\e 0es Aatch the esca'e character (*SC:: ESC( not \ )-
\E H En! case (\L( \U) or /uote"eta (\Q) translation-
\f 0es Aatch the #or" #ee! character (FF)-
\L No True at en!$o#$"atch 'osition o# 'rior $//2-
\l H Lowercase the net character only-
\L H Lowercase till \E-
\n 0es Aatch the newline character (usually NL( but CR
on Aacs)-
\N{NAME} 0es Aatch the na"e! char (\N{2reeA8@D2$a})-
\3{PROP} 0es Aatch any character with na"e! 'ro'erty-
\M{PROP} 0es Aatch any character without the na"e! 'ro'erty-
\Q H Iuote (!e$"eta) "etacharacters till \E-
\r 0es Aatch the return character (usually CR( but NL
on Aacs)-
\% 0es Aatch any whites'ace character-
\@ 0es Aatch any nonwhites'ace character-
\t 0es Aatch the tab character (HT)-
\u H Titlecase net character only-
\U H U''ercase (not titlecase) till \E-
\# 0es Aatch any +wor!, character (al'hanu" 'lus +J,)-
\< 0es Aatch any nonwor! character-
\xHEX 0es Aatch the character gi9en one or two he !igits-
\x{abcd} 0es Aatch the character gi9en in hea!eci"al-
\= 0es Aatch Unico!e +co"bining character se/uence,
string-
\? No True at en! o# string only-
\J No True at en! o# string or be#ore o'tional newline-
Classic Character Classes !%
Symbol Meaning As Bytes As utf8
\: Digit F0(NG \3{H%KD2Dt}
\K Non!igit F60(NG \M{H%KD2Dt}
\% 1hite F \t\n\r\fG \3{H%@3ace}
\@ Nonwhites'ace F6 \t\n\r\fG \M{H%@3ace}
\# 1or! character Fa(?A(J0(NOG \3{H%<9r:}
\< Non$(wor! character) F6a(?A(J0(NOG \M{H%<9r:}
C"+p"site 7nic"de Pr"perties !$2!(
Property Equivalent
H%A@CHH F\x00(\x7fG
H%Alnu$ F\3{H%Ll}\3{H%Lu}\3{H%Lt}\3{H%L9}\3{H%N:}
H%Al3Pa F\3{H%Ll}\3{H%Lu}\3{H%Lt}\3{H%L9}
H%Cntrl \3{H%C}
H%KD2Dt \3{H%N:}
H%Lra3P F6\3C\3{H%@3ace}G
H%L9#er \3{H%Ll}
H%MrDnt \M{H%C}
H%Munct \3{H%M}
H%@3ace F\t\n\f\r\3{H%J}G
H%U33er F\3{H%Lu}\3{H%Lt}G
H%<9r: FO\3{H%Ll}\3{H%Lu}\3{H%Lt}\3{H%L9}\3{H%N:}G
H%=KD2Dt F0(Na(fA(QG
2erl also 'ro9i!es the #ollowing co"'osites3
Property Meaning Normative
H%C Crazy control characters an! such 0es
H%L Letters 2artly
H%M Aar&s 0es
H%N Nu"bers 0es
H%M 2unctuation No
H%@ Sy"bols No
H%J Se'arators (Ke'aratorsC) 0es
POSI82St4le Character Classes !%*2!%-
Class Meaning
alnu$ *ny al'hanu"eric( that is an al3Pa or a :D2Dt-
al3Pa *ny letter- (ThatLs a lot "ore letters than you thin&( unless
youLre thin&ing Unico!e( in which case itLs still a lot-)
a%cDD *ny character with an or!inal 9alue between 4 an! 65M-
cntrl *ny control character- Usually characters that !onLt
'ro!uce out'ut as such( but instea! control the ter"inal
so"ehowN #or ea"'le( newline( #or" #ee!( an! bac&s'ace-
:D2Dt * character re'resenting a !eci"al !igit( such as 4 to O-
(:nclu!es other characters un!er Unico!e-) E/ui9alent to E!-
2ra3P *ny al'hanu"eric or 'unctuation character-
l9#er * lowercase letter-
3rDnt *ny al'hanu"eric or 'unctuation character or s'ace-
3unct *ny 'unctuation character-
%3ace *ny s'ace character- :nclu!es tab( newline( #or" #ee!( an!
carriage return (an! a lot "ore un!er Unico!e-) E/ui9alent
to Es-
u33er *ny u''ercase (or titlecase) letter-
#9r: *ny i!enti#ier character( either an alnu$ or un!erline-
x:D2Dt *ny hea!eci"al !igit- E/ui9alent to F0(Na(fA(QG-
0ou can negate the 2=S:F character classes by 're#iing the class
na"e with a 6 #ollowing the F8- (This is a 2erl etension-)

S-ar putea să vă placă și