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).
-
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.
|