(?(?{ print "$1 $2 $3\n" })(*FAIL)|(*ACCEPT))

I don't understand the purpose of the  (*ACCEPT) false clause in the quoted code fragment. Because the print will always return true (unless there's some terrible I/O failure :), this clause will never be executed. The following versions of the code (with and without (*ACCEPT)) test the same in all 5.10+ Perl versions I have in captivity (see this):

use 5.010; # need (?(?{ code }) pattern) use Test::More 'no_plan'; use Test::NoWarnings; note 'perl version ', $]; for my $rw ('.+', '.+ w?') { for my $rx ('.+', '.+ x?') { for my $ry ('.+', '(?: . y?)+') { my $captures = qr{ ($rw) ($rx) ($ry) }xms; local our @ra; use re 'eval'; '01234' =~ m{ \A $captures \z # (?(?{ push @ra, [ $1, $2, $3 ] }) (*F) | (*ACCEPT)) (?(?{ push @ra, [ $1, $2, $3 ] }) (*F)) }xms; is_deeply \@ra, [ [ qw(012 3 4) ], [ qw(01 23 4) ], [ qw(01 2 34) ], [ qw(0 123 4) ], [ qw(0 12 34) ], [ qw(0 1 234) ], ], $captures; } # end for $ry } # end for $rx } # end for $rw done_testing;
(Of course, the push statement always returns true.) The true magick seems to reside in the use of the regex conditional expression.

Output:

c:\@Work\Perl\monks\kroki>perl permute_via_regex_1.pl # perl version 5.014004 ok 1 - (?^msx: (.+) (.+) (.+) ) ok 2 - (?^msx: (.+) (.+) ((?: . y?)+) ) ok 3 - (?^msx: (.+) (.+ x?) (.+) ) ok 4 - (?^msx: (.+) (.+ x?) ((?: . y?)+) ) ok 5 - (?^msx: (.+ w?) (.+) (.+) ) ok 6 - (?^msx: (.+ w?) (.+) ((?: . y?)+) ) ok 7 - (?^msx: (.+ w?) (.+ x?) (.+) ) ok 8 - (?^msx: (.+ w?) (.+ x?) ((?: . y?)+) ) 1..8 ok 9 - no warnings 1..9

Of course, your final thought still holds true: none of this is guaranteed against future regex engine optimizations and other "improvements"!


Give a man a fish:  <%-{-{-{-<


In reply to Re^2: Bug with finding all regexp matches by AnomalousMonk
in thread Bug with finding all regexp matches by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.