X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlretut.pod;h=be4693dd0f87723a3cf525a45142d9ec5cd4d2f2;hb=8927c9d824bf5d960d90467f403bdfa9cbaff854;hp=cc8f5c4c9ba169edfc1a94a9c582655d75acd022;hpb=da75cd15705fec9f427a4cc8a647f3b6919c6e04;p=p5sagit%2Fp5-mst-13.2.git
diff --git a/pod/perlretut.pod b/pod/perlretut.pod
index cc8f5c4..be4693d 100644
--- a/pod/perlretut.pod
+++ b/pod/perlretut.pod
@@ -158,13 +158,14 @@ that a metacharacter can be matched by putting a backslash before it:
"2+2=4" =~ /2\+2/; # matches, \+ is treated like an ordinary +
"The interval is [0,1)." =~ /[0,1)./ # is a syntax error!
"The interval is [0,1)." =~ /\[0,1\)\./ # matches
- "/usr/bin/perl" =~ /\/usr\/local\/bin\/perl/; # matches
+ "/usr/bin/perl" =~ /\/usr\/bin\/perl/; # matches
In the last regexp, the forward slash C<'/'> is also backslashed,
because it is used to delimit the regexp. This can lead to LTS
(leaning toothpick syndrome), however, and it is often more readable
to change delimiters.
+ "/usr/bin/perl" =~ m!/usr/bin/perl!; # easier to read
The backslash character C<'\'> is a metacharacter itself and needs to
be backslashed:
@@ -550,7 +551,7 @@ to give them a chance to match.
The last example points out that character classes are like
alternations of characters. At a given character position, the first
-alternative that allows the regexp match to succeed wil be the one
+alternative that allows the regexp match to succeed will be the one
that matches.
=head2 Grouping things and hierarchical matching
@@ -587,7 +588,7 @@ are
Alternations behave the same way in groups as out of them: at a given
string position, the leftmost alternative that allows the regexp to
-match is taken. So in the last example at tth first string position,
+match is taken. So in the last example at the first string position,
C<"20"> matches the second alternative, but there is nothing left over
to match the next two digits C<\d\d>. So perl moves on to the next
alternative, which is the null alternative and that works, since
@@ -689,10 +690,11 @@ inside goes into the special variables C<$1>, C<$2>, etc. They can be
used just as ordinary variables:
# extract hours, minutes, seconds
- $time =~ /(\d\d):(\d\d):(\d\d)/; # match hh:mm:ss format
- $hours = $1;
- $minutes = $2;
- $seconds = $3;
+ if ($time =~ /(\d\d):(\d\d):(\d\d)/) { # match hh:mm:ss format
+ $hours = $1;
+ $minutes = $2;
+ $seconds = $3;
+ }
Now, we know that in scalar context,
S > returns a true or false
@@ -1403,6 +1405,8 @@ off. C<\G> allows us to easily do context-sensitive matching:
The combination of C/g> and C<\G> allows us to process the string a
bit at a time and use arbitrary Perl logic to decide what to do next.
+Currently, the C<\G> anchor is only fully supported when used to anchor
+to the start of the pattern.
C<\G> is also invaluable in processing fixed length records with
regexps. Suppose we have a snippet of coding region DNA, encoded as
@@ -1415,7 +1419,7 @@ naive regexp
$dna = "ATCGTTGAATGCAAATGACATGAC";
$dna =~ /TGA/;
-doesn't work; it may match an C, but there is no guarantee that
+doesn't work; it may match a C, but there is no guarantee that
the match is aligned with codon boundaries, e.g., the substring
S > gives a match. A better solution is
@@ -1653,12 +1657,11 @@ Unicode characters in the range of 128-255 use two hexadecimal digits
with braces: C<\x{ab}>. Note that this is different than C<\xab>,
which is just a hexadecimal byte with no Unicode significance.
-B: in perl 5.6.0 it used to be that one needed to say C