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 $_