hola perl dudes & dudettes;
obwarning:
this question might interest those who have a mild interest
in XML::Dumper or serialization more... than those who don't.
the problem:
in an attempt to serialize certain pesky struct-alikes
as fashionably as possible, i turned to module XML::Dumper,
which does the job very slinkily indeed.
however, i have been puzzled by the behaviour of 2 core
functions in this module: xml_compare, and xml_identity,
both of which take chunks of xml and, well, inform about
"identity in content" of xml and "identity in instantiation".
here is an example of their use:
use XML::Dumper;
my $struct = {
"ferret" => ["sredni", "vashtar"],
"hen" => "anabaptist",
};
my $xdumper = new XML::Dumper;
# generate xml equiv to struct
my $ssxmlified = $xdumper->pl2xml($struct);
# write it to file as well
$xdumper->pl2xml($struct, "oot.txt");
# reconstitute our struct from the file
my $structreconstituted = $xdumper->xml2pl("oot.txt");
# generate xml===reconstituted struct
$rexmlified = $xdumper->pl2xml($structreconstituted);
my $sscequal = $xdumper->xml_compare($rexmlified, $ssxmlified);
my $ssiequal = $xdumper->xml_identity($rexmlified, $ssxmlified);
printf "xml_compare: %s\n", ($sscequal? "true" : "false");
printf "xml_identity:%s\n", ($ssiequal? "true" : "false");
although the xml generated is entirely the same
in content (*not* memory locations), neither xml_compare
nor xml_identity return true. the latter i understand,
the former frustrates me, as i was hoping to use it to
check whether 2 data structures were equal in content.
does anyone know of any way, slick or otherwise, to
achieve this goal?
thanks for any response.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.