Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Syntactic Confectionery Delight
 
PerlMonks  

Re: Data::Dumper Efficiency Problem

by repson (Chaplain)
on Jan 04, 2001 at 01:34 UTC ( [id://49679]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Data::Dumper Efficiency Problem

Another method depending on data is XML::Simple.
XMLout can take a filename or filehandle which may reduce memory used during running by immediate output instead of storing (I don't know if it does). XMLin is supposed to always create the original data structure...

It does allow buzzword compliance, and a structure parseable without needing perl.

As to your original question, Data::Dumper may be creating self referential output, this means that is has to remember and constantly process everything that has already passed through it. Read the module docs to find out if this may be happening and what you should do about it (call $OBJ->Reset under the OO interface possibly, depending on how you are doing things).

Replies are listed 'Best First'.
Re: Re: Data::Dumper Efficiency Problem
by mirod (Canon) on Jan 04, 2001 at 01:49 UTC

    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).

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://49679]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.