Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Creation of Hash necessary?

by poj (Priest)
on Aug 14, 2014 at 08:51 UTC ( #1097400=note: print w/ replies, xml ) Need Help??


in reply to Creation of Hash necessary?

If your data was well formed XML you could use XML::Twig

#!perl use strict; use XML::Twig; my $xml = do { local $/; <DATA> }; my $twig = new XML::Twig( twig_handlers =>{ class => \&class}, ); $twig->parse($xml); sub class { my ($t,$elt) = @_; for my $shape ($elt->children){ $shape->set_att('class',$elt->att('id')); $shape->print; print "\n"; } } __DATA__ <data> <class id="abc"> <polygon coordinates=".."/> <polygon coordinates=".."/> <rectangle coordinates=".."/> </class> <class id="def"> <polygon coordinates=".."/> <rectangle coordinates=".."/> <rectangle coordinates=".."/> </class> </data>
poj


Comment on Re: Creation of Hash necessary?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (14)
As of 2015-07-31 17:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls