Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by AnomalousMonk (Monsignor)
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 chilling in the Monastery: (13)
As of 2014-07-30 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls