Sunday, February 24, 2008
Learning Perl, 4th Edition Notes 0x7
Learning Perl, 4th Edition Notes 0x7 by DaNmarner
* Patterns-in-paired-forward-slashes is actually a shortcut of "m / pattern /". The delimiers could be chosen from other nonpaired characters or some paired characters.
* Modifiers, or flags, can change a regular expression's behavior from the default. They are appended as a group right after a regular expression. To be specific:
i makes the matching case-insensitive;
s makes dot matches any character, even newline (\n);
x allows you to add spaces to a pattern to make it look better.
* Anchors hold the matching at a particular point instead of floating around the whole string. Amount which:
carats (^) mark the beginning;
dollar signs ($) mark the end;
\b marks either end of a word;
\B is the opposit of \b;
* The binding charater, defined as "=~", tells perl to match the pattern on the left against the string on the left.
* Patterns are intepolatable in double quoted strings.
* In a pattern, Perl stores the part that the n th set of paratheses match into $n. These so-called match variables stay around until the next time a pattern match successfully.
* Eventually a string matched by a pattern is divided into at least three parts, which are stored automatically by perl in to the variable names followed by their description below:
the part that the pattern matches ($&);
the part that leads the first part ($`);
the part that succeeds the first part ($');
* The syntax for the more general quantifiers are pairs of curl braces following the quantified item, within which is the number(s) of the repeated time. There can be only one number that indicates the exact quantity, or two numbers seperated by a comma that tell the range of the quantity. In the seconed case, the seconed number is optional, leaving it blank indicates that there's no upper limit to the quantity.
* The high-to-low precedence of the metacharacters in a pattern is briefely: grouping parentheses, quantifiers, anchors and sequence, vertical bars.
* Further info about regular information in Perl can be found in perlre, perlrequick and perlretut manpages.
Labels:
Notes,
Perl,
Programming,
Regular Expression,
Script
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment