Perl Quick Reference Card

ADVERTISEMENT

Perl Quick Reference Card
Operator Precedence (continued)
87
tr/// Modifiers
156
Complement SEARCHLIST.
Associativiy
Arity
Precedence Class
/c
version 0.02 – editor: John Bokma – freelance programmer
Delete found but unreplaced characters.
/d
Right
3
?:
DRAFT VERSION, check:
Squash duplicate replaced characters.
/s
Right
2
and so on
= += -= *=
Backslashed Character Escapes
61
Left
2
, =>
General Regex Metacharacters
159
Newline (usually LF)
Null character (NUL)
\n
\0
Right
0+
List operators (rightward)
Carriage return (usually CR)
ESC in octal
Symbol Atomic Meaning
\r
\033
Right
1
not
Horizontal tab (HT)
DEL in hexadecimal
Varies
De-meta next nonalphanumeric character, meta
\t
\x7f
\…
Left
2
and
Form feed (FF)
Control-C
next alphanumeric character (maybe).
\f
\cC
Left
2
or xor
Backspace (BS)
Unicode, ☺(smiley)
No
Alternation (match one or the other).
…|…
\b
\x{263a}
File Test Operators
98
Yes
Grouping (treat as a unit).
Alert (BEL)
Named character
(…)
\a
\N{NAME}
Yes
Character class (match one character from a set).
Escape (ESC)
[…]
\e
File is readable by effective UID/GID.
-r
File is writable by effective UID/GID.
-w
Translation Escapes
61
File is executable by effective UID/GID.
-x
No
True at beginning of string (or after a newline,
^
Force next character to uppercase (“titlecase” in Unicode).
\u
File is owned by effective UID/GID.
-o
maybe).
Force next character to lowercase.
\l
File is readable by real UID/GID.
-R
Yes
Match one character (except newline, normally).
.
Force all following characters to uppercase
\U
File is writable by real UID/GID.
-W
No
True at end of string (or before any newline,
$
Force all following characters to lowercase
\L
File is executable by real UID/GID.
-X
maybe).
Backslash all following non-"word" characters (quotemeta)
\Q
File is owned by real UID/GID.
-O
End
,
or
.
\E
\U
\L,
\Q
Regex Quantifiers
159-160
File exists.
-e
File has zero size
Quantifier Atomic Meaning
Quote Constructs
63
-z
File has nonzero size (returns size).
-s
No
Match 0 or more times (maximal).
*
Customary
Generic
Meaning
Interpolates
File is a plain file.
No
Match 1 or more times (maximal).
-f
+
File is a directory.
No
Match 0 or 1 time (maximal).
-d
?
Literal string
No
''
q//
File is a symbolic link.
No
Match exactly
times.
-l
{COUNT}
COUNT
Literal string
Yes
""
qq//
File is a named pipe (FIFO).
No
Match at least
times (maximal).
-p
{MIN,}
MIN
Command execution
Yes
``
qx//
File is a socket.
No
Match at least
but not more than
-S
{MIN,MAX}
MIN
MAX
Word list
No
()
qw//
File is a block special file.
times (maximal).
-b
Pattern match
Yes
//
m//
File is a character special file.
-c
Pattern substitution
Yes
s///
s///
Filehandle is open to a tty.
*?
No
Match 0 or more times (minimal).
-t
Character translation
No
y///
tr///
+?
No
Match 1 or more times (minimal).
File has setuid bit set.
-u
Regular expression
Yes
""
qr//
??
No
Match 0 or 1 time (minimal).
File has setgid bit set.
-g
No
Match at least
times (minimal).
{MIN,}?
MIN
File has sticky bit set.
Note:
no interpolation is done if you use single quotes for delimiters.
-k
No
Match at least
but not more than
File is a text file.
{MIN,MAX}?
MIN
MAX
-T
Operator Precedence
87
times (minimal).
File is a binary file (opposite of -T).
-B
Associativiy
Arity
Precedence Class
Age of file (at startup) in (fractional) days since modification.
-M
Extended Regex Sequences
160
None
0
Terms, and list operators (leftward)
Age of file (at startup) in (fractional) days since last access.
-A
Extension
Atomic Meaning
Left
2
Age of file (at startup) in (fractional) days since inode change.
->
-C
No
Comment, discard.
(?#…)
None
1
++ --
Pattern Modifiers
147
Yes
Cluster-only parentheses, no capturing.
(?:…)
Right
2
**
No
Enable/disable pattern modifiers.
Ignore alphabetic case distinctions (case insensitive).
(?imsx-imsx)
/i
Right
1
and unary
and unary
! ~ >
+
-
Yes
Cluster-only parentheses plus modifiers.
Let
match newline and ignore deprecated
variable.
(?imsx-imsx:…)
/s
.
$*
Left
2
=~ !~
No
True if lookahead assertion succeeds.
Let
and
match next embedded
.
(?=…)
/m
^
$
\n
Left
2
* / % x
No
True if lookahead assertion fails.
Ignore (most) whitespace and permit comments in pattern.
(?!…)
/x
Left
2
+ - .
No
True if lookbehind assertion succeeds.
Compile pattern only once.
(?<=…)
/o
Left
2
<< >>
No
True if lookbehind assertion fails.
(?<!…)
Right
0,1
Named unary operators
Additional m// Modifiers
150
Yes
Match nonbacktracking subpattern.
(?>…)
None
2
< > <= >= lt gt le ge
Globally find all matches.
/g
No
Execute embedded Perl code.
(?{…})
None
2
== != <=> eq ne cmp
Allow continued search after failed
match.
/cg
/g
Yes
Match regex from embedded Perl code.
(??{…})
Left
2
&
Yes
Match with if-then-else pattern.
(?(…)…|…)
Left
2
Additional s/// Modifiers
153
| ^
Yes
Match with if-then pattern.
(?(…)…)
Left
2
&&
Replace globally, that is, all occurences.
/g
Left
2
||
Evaluate the right side as an expression.
/e
None
2
.. ...

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2