Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
if( $args !~ / (*FAIL) | \-rs(\s+)(\S+) # | \-? (\s+)(\S+) | \-P (\s+)(\S+) | \-p (\s+)(\S+) /x ){ ... }

I don't understand the purpose of the  (*FAIL) operator (see Special Backtracking Control Verbs in perlre in Perl versions 5.10+ (update: see also Backtracking control verbs in perlretut - but that's not actually as extensive as the discussion in perlre)) in the quoted regex. At any position in the  | alternation,  (*FAIL) will simply force the RE to try the next alternation; if it's at the last position, all the preceding pattern matches would have failed and the alternation would fail anyway without (*FAIL).

c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; for my $s (qw(XXX ppp)) { print qq{for '$s' string}; if ($s !~ m{ (*F) | p | q }xms) { print ' with (*F): no match, !~ +true' } if ($s !~ m{ Z | p | q }xms) { print ' with Z: no match, !~ +true' } if ($s !~ m{ p | q }xms) { print ' no (*F): no match, !~ +true' } print ' -------'; } " for 'XXX' string with (*F): no match, !~ true with Z: no match, !~ true no (*F): no match, !~ true ------- for 'ppp' string -------
Note that for all these variations, for string 'XXX' there is never a match (!~ is always true); string 'ppp' always matches (!~ always false).

... not equivalently, because there are 8 capturing groups instead of 2 ...

If you're using  (*FAIL) you must be using Perl version 5.10+, so you also have the  (?|pattern) "branch reset" operator (see Extended Patterns in perlre). This allows you to go back to having two capture groups again!

Update: Changed example code slightly to better reflect discussion.


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


In reply to Re^6: regex return true instead of false (precedence) by AnomalousMonk
in thread regex return true instead of false by ovedpo15

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found