Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

by SimonClinch (Deacon)
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

Replies are listed 'Best First'.
Re^2: Convert XML To Perl Data Structures Using XML::Twig
by Limbic~Region (Chancellor) on May 24, 2011 at 16:17 UTC
    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://906525]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-06-23 14:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.