X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlretut.pod;h=6afae2187bbaf737c7e6da8d84792555ea4cc520;hb=ee6b43cc19efb39ed8a2fdad01d701e59dbdd946;hp=f4e9bb64405d98c186de608f24c17b56ed9110da;hpb=210b36aa2e9e009554be8970c3315c2658c0384f;p=p5sagit%2Fp5-mst-13.2.git
diff --git a/pod/perlretut.pod b/pod/perlretut.pod
index f4e9bb6..6afae21 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:
@@ -499,7 +500,7 @@ Here are examples of C/s> and C/m> in action:
$x =~ /girl.Who/m; # doesn't match, "." doesn't match "\n"
$x =~ /girl.Who/sm; # matches, "." matches "\n"
-Most of the time, the default behavior is what is want, but C/s> and
+Most of the time, the default behavior is what is wanted, but C/s> and
C/m> are occasionally very useful. If C/m> is being used, the start
of the string can still be matched with C<\A> and the end of string
can still be matched with the anchors C<\Z> (matches both the end and
@@ -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
@@ -1323,9 +1325,9 @@ If you change C<$pattern> after the first substitution happens, perl
will ignore it. If you don't want any substitutions at all, use the
special delimiter C:
- $pattern = 'Seuss';
+ @pattern = ('Seuss');
while (<>) {
- print if m'$pattern'; # matches '$pattern', not 'Seuss'
+ print if m'@pattern'; # matches literal '@pattern', not 'Seuss'
}
C acts like single quotes on a regexp; all other C delimiters
@@ -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
@@ -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