On Dec 12, 2005, at 22:10, Owen wrote:

Xavier Noria wrote:
On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:

I have a string that looks like this :
<counter id="183268" since="SDOPERFV16" aggr="Sum"
name="pcmTcuFaultOutOfService"/>


m// in list contex may help:

    my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};


I despair of ever understanding REs

How does the above work

m       Match
{       inside these braces (as the delimiter?)
id="       the characters   id="
(       Start the capture for $id
[^"]       The list of characters beginning with "
        But wasn't that done on line 3 where we
        looked for a  "
*       any number of characters
)       end of capture for $id
"  the end  " for the data element captured
.*      anything until
name="     etc do it all again till

}       ending delimiter

Good exercise!

The answer is short, but since you already did this effort I'll tell you a way to figure out what's missing that's very close to your approach: Ask japhy's YAPE::Regex::Explain about it:

    use YAPE::Regex::Explain;
print YAPE::Regex::Explain->new(qr{id="([^"]*)".*name="([^"]*)"/ >})->explain;

-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to