Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Strip that XML!

by perl_addict (Initiate)
on Apr 07, 2011 at 06:27 UTC ( [id://897946]=note: print w/replies, xml ) Need Help??


in reply to Strip that XML!

Just a small correction to above perl snipplet. As far as my understanding we cannot decalre $_ as "my" since its a special global variable. This code will throw a compilation error in this case. We need to declare $_ as local to work it in proper way.

I would rather suggest using following code:-

use strict; my $str_xml='<xml> <email>toto@foo.com</email><name>Toto</name> <email>tata@bar.com</email><name>Tata</name> <email>tutu@baz.com</email><name>Tutu</name> </xml>'; my @email = ($str_xml =~ /<email>(.*?)<\/email>/g); my @name = ($str_xml =~ /<name>(.*?)<\/name>/g); print "email: @email\n"; print "name: @name\n";

Replies are listed 'Best First'.
Re: Answer: Strip that XML!
by Anonymous Monk on Apr 07, 2011 at 12:19 UTC
    FWIW, with a recent enough version of perl,you can have my $_

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found