Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: How to store matched $1 values one by one to array?

by AnomalousMonk (Abbot)
on Feb 02, 2013 at 14:01 UTC ( #1016714=note: print w/ replies, xml ) Need Help??


in reply to Re: How to store matched $1 values one by one to array?
in thread How to store matched $1 values one by one to array?

A minor variation using the  \K (5.10+) and  s///r (5.14+) regex operators, and no capture groups. (Note: I use  \x22 instead of  " (double-quote) in the  s///r substitution because the Windoze CLI gets a little freaky over unpaired double-quotes.)

>perl -wMstrict -MData::Dump -le "my $line = q{xxx:agent_id=>foo,yyy:agent_id=>b\"a\"r,zzz:agent_id=>\"baz\",qqq +}; ;; my @agents = map s{\x22}{}xmsgr, $line =~ m{ :agent_id=> \K [^,]+ }xmsg; ;; dd \@agents; " ["foo", "bar", "baz"]


Comment on Re^2: How to store matched $1 values one by one to array?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2015-07-02 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls