Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

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


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

Here's something that may be close to what you're seeking:

>perl -wMstrict -le "my $line = 'xxx:agent_id=>foo,yyy:agent_id=>b\"a\"r,zzz:agent_id=>\"baz\",qqq' +; print qq{'$line'}; ;; my @agents; while ($line =~ m{ :agent_id=> (.+?) , }xmsg) { my $agent_id = $1; printf qq{extracted agent id: '$agent_id' }; $agent_id =~ s/\"//g; print qq{fixed agent id: '$agent_id'}; push @agents, $agent_id; } printf qq{'$_' } for @agents; " 'xxx:agent_id=>foo,yyy:agent_id=>b"a"r,zzz:agent_id=>"baz",qqq' extracted agent id: 'foo' fixed agent id: 'foo' extracted agent id: 'b"a"r' fixed agent id: 'bar' extracted agent id: '"baz"' fixed agent id: 'baz' 'foo' 'bar' 'baz'

In addition to perlrequick, see also perlre (the guts and the glory) and perlretut (a good tutorial, highly recommended).


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2015-07-04 15:25 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 (60 votes), past polls