Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

though I've been reading PM for quite a while it's the first time to ask a question now. Please forgive me if I post in a wrong section.

I'm trying to dump a Perl datastructure to a file in order to save on disc for
(a) reuse on subsequent runs of the scripts
(b) enable backups

Backups might be restored to a different mashine as well as moved between testing and live system.

In order not to reinvent any wheel I'm playing with XML::Dumper which works fine on my testing system.

Opposed to the docs the dumped structure contains memory_address="xxxx" attributes like this:

<perldata> <hashref memory_address="0x8634534"> <item key="COOKIE"> <arrayref memory_address="0x8634438"> <item key="0"> <hashref memory_address="0x862c4a4"> <item key="items"> <arrayref memory_address="0x862c48c"> </arrayref> </item> <item key="keys"> <arrayref memory_address="0x862c468"> <item key="0">name</item> </arrayref> </item> <item key="matchtype">non-empty</item> <item key="output_filter">2</item> </hashref> </item> bla...
Am I doing anything wrong calling XML::Dumper like this?
use XML::Dumper; my $xmlfile = 'filter.xml'; my $dump = new XML::Dumper; $dump->pl2xml( $input_filter, $xmlfile );
Question:
Assuming the dumped memory_address is an intended behaviour, will it have any (negative) effect if the dumped file is moved from one server to another (potentially different operating system) and used for rebuilding the Perl datastructure on the second mashine?

Any hint gladly appreciated.

Thx for reading.

RL

Replies are listed 'Best First'.
Re: XML::Dumper - Dump to file cross-server safe?
by Fletch (Bishop) on Apr 11, 2007 at 15:39 UTC

    Glancing through the source for XML::Dumper, it looks as if the memory_address attribute is used basically as a key to identify portions of the data structure which are references to the same entity. It then makes the reconstructed data point to the corresponding existing reference in the new copy. YAML (and YAML::Syck) provide a similar functionality with anchors and aliases.

    So it doesn't look to be used verbatim, merely used as a unique ID for some portion of the serialized data (granted the name of the key is misleading and your confusion understandable). Just read the attribute name as id and treat it as opaque (as the module does) and don't worry about it.

      Please don't wonder. - Registered meanwhile :-)
Re: XML::Dumper - Dump to file cross-server safe?
by ikegami (Patriarch) on Apr 11, 2007 at 15:33 UTC
    I think the address is not used as an address, but as a unique identifier. It allows the serializing (dumping) of structures such as the one below without cloning substructures referenced twice on load.
    $ar = []; $structure = [ $ar, $ar ];