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

Re: Named Captures

by Corion (Pope)
on Oct 06, 2010 at 11:09 UTC ( #863756=note: print w/replies, xml ) Need Help??

in reply to Named Captures

You don't have a loop around the /g match, so it only matches once and uses the first matching alternative, "a".

The following loops over the string and outputs %+ whenever it matches something:

> perl -wE"while ('abcde'=~m[(?<a>a)|(?<b>b)|(?<c>c)|(?<d>d)]g){say'-- +';say for keys%+}" -- a -- b -- c -- d

I don't think that %+ will ever be filled with keys from more than one part of an alternation, so you'll never find more than one key in your example. To get all keys you'll likely need to introduce an explicit ordering or enumerate the alternatives.

Replies are listed 'Best First'.
Re^2: Named Captures
by BrowserUk (Pope) on Oct 06, 2010 at 11:19 UTC

    So, each iteration of the implicit /g loop will overwrite %+. Ie. they don't accumulate?

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863756]
[robby_dobby]: I attended a couple conferences (both in India). Left me with a renewed enthusiasm to do more, only to see it disappear in a few days!
[LanX]: Then come to YAPC EU in Amsterdam ...
[robby_dobby]: LanX: But that's in Africa! More like YAPC::Africa
choroba fears Amsterdam might fill him with enthusiasm to do nothing
[robby_dobby]: Uff, too expensive :-(
[LanX]: ... I found YAPC EU more entertaining (and international )than YAPC NA
[robby_dobby]: What's the site for YAPC::EU?
[LanX]: Robby Dobby no IIRC Sinai is already part of Asia
[robby_dobby]: page for yapceu is out of date by 2 years
[robby_dobby]: LanX: Sharm-el-Sheikh is in Egypt

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-04-24 15:57 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.