MG SRC="4.gif">    
Syntax
Category  list operator (i/o)
Arguments  expression

Arguments  handle
Arguments  none
Definition

This function writes a formatted record to the file handle (or the file handle that the expression evaluates to). If no file handle is specified, the default is STDOUT; this can be altered by using select() if necessary.

A format for use by that file handle must have been declared using the format() function. This defaults to the name of the file handle being used, but other format names can be associated with the current write() operation using the $FORMAT_NAME ($~) special variable.


y///

Compliance
    
Syntax
Category  (string)
Arguments  y/searchlist/replacelist/<options>
Return Value  numeric
Definition

The y/// operator is a synonym for the translation operator tr///.



Chapter 11 -- Perl Regular Expressions

Chapter 11

Perl Regular Expressions


CONTENTS

A regular expression is a way of specifying a pattern so that some strings match the pattern and some strings do not. Parts of the matching pattern can be marked for use in operations such as substitution. This is a powerful tool for processing text, especially when producing text-based reports. Many UNIX utilities use a form of regular expressions as a pattern matching mechanism (for example, egrep) and Perl has adopted this concept, almost as its own.

Like arithmetic expressions, regular expressions are made up of a sequence of legal symbols linked with legal operators. Table 11.1 lists all of these operators and symbols in one table for easy reference. If you are new to regular expressions you may find the description in Chapter 7, "Perl Overview," informative.

Table 11.1  Regular Expression Meta-Characters, Meta-Brackets, and Meta-Sequences

Expression
Description
Meta-Characters 
^
This meta-character-the caret-will match the beginning of a string or, if the /m option is used, match the beginning of a line. It is one of two pattern anchors-the other anchor is the $.
.
This meta-character will match any single character except for the newline unless the /s option is specified. If the /s option is specified, then the newline will also be matched.
$
This meta-character will match the end of a string or, if the /m option is used, match the end of a line. It is one of two pattern anchors-the other anchor is the ^.
|
This meta-character-called alternation-lets you specify two values that can cause the match to succeed. Forinstance, m/a|b/ means that the $_ variable must contain the "a" or "b" character for the match to succeed.
*
This meta-character indicates that the thing immediately to the left should be matched zero or more times in order to be evaluated as true; thus, .* matches any number of character.
+
This meta-character indicates that the thing immediately to the left should be matched one or more times in order to be evaluated as true.
?
This meta-character indicates that the thing immediately to the left should be matched zero or one times in order to be evaluated as true. When used in conjunction with the +, ?, or {n, m} meta-characters and brackets, it means that the regular expression should be non-greedy and match the smallest possible string.
Meta-Brackets 
()
The parentheses let you affect the order of pattern evaluation and act as a form of pattern memory. See Chapter 8, "Perl Special Variables," for more details.
(?...)
If a question mark immediately follows the left parentheses, it indicates that an extended mode component is being specified (new to Perl 5).
(?#comment)
Extension: comment is any text.
(?:regx)
Extension: regx is any regular expression, but parentheses are not saved as a backreference.
(?=regx)
Extension: allows matching of zero-width positive lookahead characters (that is, the regular expression is matched but not returned as being matched).
(?!regx)
Extension: allows matching of zero-width negative lookahead characters (that is, negated form of (=regx)).
(?options)
Extension: applies the specified options to the pattern bypassing the need for the option to specified in the normal way. Valid options are: i (case-insensitive), m (treat as multiple lines), s (treat as single line), x (allow whitespace and comments).
{n, m}
The braces let you specify how many times the thing immediately to the left should be matched. {n} means that it should be matched exactly n times. {n,} means it must be matched at least n times. {n, m} means that it must be matched at least n times but not more than m times.
[]
The square brackets let you create a character class. For instance, m/[abc]/ will evaluate to true if any of a, b, or c is contained in $_.The square brackets are a more readable alternative to the alternation meta-character.
Meta-Sequences 
\
This meta-character "escapes" the character that follows. This means that any special meaning normally attached to that character is ignored. For instance, if you need to include a dollar sign in a pattern, you must use \$ to avoid Perl's variable interpolation. Use \\ to specify the backslash character in your pattern.
\nnn
Any octal byte (where nnn represents the octal number-this allows any character to be specified by its octal number).
\a
The alarm character (this is a special character that, when printed, produces a warning bell sound).
\A
This meta-sequence represents the beginning of the string. Its meaning is not affected by the /m option.
\b
This meta-sequence represents the backspace character inside a character class, otherwise it represents a word boundary. A word boundary is the spot between word (\w) and non-word (\W) characters. Perl thinks that the W meta-sequence matches the imaginary characters of the end of the string.
\B
Match a non-word boundary.
\cn
Any control character (where n is the character, for example, \cY for Ctrl+Y).
\d
Match a single digit character.
\D
Match a single non-digit character.
\e
The escape character.
\E
Terminate the \L or \U sequence.
\f
The form feed character.
\G
Match only where the previous m//g left off.
\l
Change the next character to lowercase.
\L
Change the following characters to lowercase until a \E sequence is encountered.
\n
The newline character.
\Q
Quote regular expression meta-characters literally until the \E sequence is encountered.
\r