Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Convert XML To Perl Data Structures Using XML::Twig

by SimonClinch (Chaplain)
on May 24, 2011 at 16:07 UTC ( #906525=note: print w/ replies, xml ) Need Help??


in reply to Convert XML To Perl Data Structures Using XML::Twig

I would inherit XML::Twig into a simple package with only new that receives your data (and/or possibly a "set" method to do that) and a handler method that trivially processes the data from there using Twig's own handlers.

One world, one people


Comment on Re: Convert XML To Perl Data Structures Using XML::Twig
Re^2: Convert XML To Perl Data Structures Using XML::Twig
by Limbic~Region (Chancellor) on May 24, 2011 at 16:17 UTC
    SimonClinch,
    Really? That seems like a better alternative than writing your own dispatch table? Even using the built in handlers, you still have to write the subroutines themselves. I guess from an abstraction perspective it is appealing but consider my existing code looks like:
    my $twig = XML::Twig->new(); while (<$fh>) { $twig->parse($_); # ... }
    Will now need to look like:
    while (<$fh>) { my $twig = XML::Twig->new($data_struct); $twig->parse($_); # ... }
    I have no idea the extent of the performance overhead but it is probably less than the alternative:
    my $twig = XML::Twig->new($data_struct); while (<$fh>) { $twig->parse($_); # ... my $copy = deep_copy($data_struct); $data_struct = clear_structure($data_struct); }
    I am not saying it is a bad idea - it just doesn't feel clean to me.

    Cheers - L~R

      Hmm I guess it's just a question of personal style what "clean" is. But I do actually agree with the idea of the dispatch table, it's just that I would put that in the instance variable of my own class, sorry if that wasn't clear in my post. But I would need to see more of the code to have a really good idea what "clean" is relative to it, without going against your style.

      One world, one people

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2014-08-20 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (115 votes), past polls