develooper Front page | perl.perl5.porters | Postings from May 2008

It's wafer thin!

Thread Next
David Nicol
May 9, 2008 11:14
It's wafer thin!
Message ID:
--- perlop.pod  2008-05-09 12:57:06.000000000 +0000
+++      2008-05-09 13:10:35.000000000 +0000
@@ -1050,15 +1050,27 @@
 the life of the script.  However, mentioning C</o> constitutes a promise
 that you won't change the variables in the pattern.  If you change them,
 Perl won't even notice.  See also L<"qr/STRING/imosx">.

 If the PATTERN evaluates to the empty string, the last
 I<successfully> matched regular expression is used instead. In this
 case, only the C<g> and C<c> flags on the empty pattern is honoured -
 the other flags are taken from the original pattern. If no match has
 previously succeeded, this will (silently) act instead as a genuine
 empty pattern (which will always match).

+    $ranch =~ /(pig)/i or $ranch =~ /(sheep)/i or $ranch =~ /(cow)/i
+    or $ranch =~ /(chicken)/i or $ranch =~ /(horse)/i or
+    $ranch =~ /(turtle)/i or die "Are you sure <<$ranch>> is a ranch?";
+    push @animals, //g; # EMPTY PATTERN stands for last successful pattern
+=item matching in list context
 If the C</g> option is not used, C<m//> in list context returns a
 list consisting of the subexpressions matched by the parentheses in the
 pattern, i.e., (C<$1>, C<$2>, C<$3>...).  (Note that here C<$1> etc. are
 also set, and that this differs from Perl 4's behavior.)  When there are
@@ -1103,8 +1115,10 @@
 search position to the beginning of the string, but you can avoid that
 by adding the C</c> modifier (e.g. C<m//gc>).  Modifying the target
 string also resets the search position.

+=item \G assertion
 You can intermix C<m//g> matches with C<m/\G.../g>, where C<\G> is a
 zero-width assertion that matches the exact position where the previous
 C<m//g>, if any, left off.  Without the C</g> modifier, the C<\G> assertion
 still anchors at pos(), but the match is of course only attempted once.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About