Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Data::Dumper Efficiency Problem

by mirod (Canon)
on Jan 04, 2001 at 06:49 UTC ( [id://49683]=note: print w/replies, xml ) Need Help??


in reply to Re: Data::Dumper Efficiency Problem
in thread Data::Dumper Efficiency Problem

This is not the way XML::Simple works. XML::Simple is designed to let you input an XML file (with some restrictions) and use the data it contains or update it and output it back. Altough I have never tried it I would bet it will not output arbitrary data structures as XML (although that might be fun!).

On the other hand XML::Dumper and Data::DumpXML will dump data to XML. I have no idea how fast they are though (and considering Data::DumpXML is also written by Gisle AAs I don't think it will be faster than Data::Dumper).

  • Comment on Re: Re: Data::Dumper Efficiency Problem

Replies are listed 'Best First'.
Re: Re: Re: Data::Dumper Efficiency Problem
by repson (Chaplain) on Jan 04, 2001 at 07:00 UTC
    Directly from the XML::Simple docs:

    XMLout()

    Takes a data structure (generally a hashref) and returns an XML encoding of that structure. If the resulting XML is parsed using XMLin(), it will return a data structure equivalent to the original.

    That sounds similar to what Data::Dumper is being used for here.

      You are actually right, although I don't really like how XML::Simple saves data structures.

      Here is an example of what XML::Simple and XML::Dumper can do:

      #!/bin/perl -w use strict; use XML::Simple; use XML::Dumper; my $struct= { toto => [1,2,3], tata => "duh", tutu => { tutu_toto => 1, tutu_tata => 2 }, }; my $out= XMLout( $struct); print "XML::Simple: $out\n"; my $dump = new XML::Dumper; print "XML::Dumper: ", $dump->pl2xml( $struct);

      The result is:

      XML::Simple: <opt tata="duh"> <tutu tutu_tata="2" tutu_toto="1" /> <toto>1</toto> <toto>2</toto> <toto>3</toto> </opt> XML::Dumper: <perldata> <hash> <item key="tata">duh</item> <item key="tutu"> <hash> <item key="tutu_tata">2</item> <item key="tutu_toto">1</item> </hash> </item> <item key="toto"> <array> <item key="0">1</item> <item key="1">2</item> <item key="2">3</item> </array> </item> </hash> </perldata>

      I personnaly think the XML::Dumper way is cleaner but YMMV

        Now that I look at it I agree that the XML::Dumper is a cleaner data structure. But by using <hash> and <array>, the data structure doesn't make full sense outside a perl-only enviroment. However XML::Simple can emit a more portable seeming structure, especially if you specify a few options first.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found