Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
use strict; use warnings; use Data::Dump 'dd'; my $s = "a aa aaa aaaa"; $s =~ /(?<a>a+) (?<a>a+) (?:(?<a>a+)bbb)?/; dd \@{^CAPTURE}; # all captured groups dd $+{a}; # leftmost defined "a" dd ${^CAPTURE}{a}; # ditto dd $-{a}; # all defined "a"'s groups dd ${^CAPTURE_ALL}{a}; # ditto __END__ ["a", "aa"] # correct "a" # correct undef ["a", "aa", undef] "a"

Documentation is not very verbose about new %{^CAPTURE}, %{^CAPTURE_ALL} variables, they are listed as if they are English synonyms to old %+ and %-, but they are obviously not, they look plain wrong to me.

The "aaa" was deleted from @{^CAPTURE} array (or was not even added to begin with), when rightmost cluster failed to match, and deleted as array element from @{$-{a}}, but the $#{$-{a}} was not changed from wrong 2 to expected 1, hence unexpected undefined element in @{$-{a}}.

Update: Actually, w/r/t %-, re-reading the docs, there's no phrase "all defined "a"'s groups" as I stated above.

To each capture group name found in the regular expression, it associates a reference to an array containing the list of values captured by all buffers with that name (should there be several of them), in the order where they appear.

Yes, they say "all buffers with that name", but can undef be said to be "captured"? Can failed sub-expression "capture"? It's ambiguous.

Update 2: Mixing these "CAPTURE" things is broken:

#dd \@{^CAPTURE}; dd \%{^CAPTURE};

is OK, but un-commenting 1st line results in empty unblessed hash in the 2nd.


In reply to %{^CAPTURE}, %{^CAPTURE_ALL} and %- don't produce expected output by vr

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 perusing the Monastery: (7)
As of 2024-04-19 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found