This has me confounded. Any help would be greatly appreciated. I have a blessed hash: $data
print Data::Dumper($data)
gives me this:
///////////////////////////////////////////////////////////////// bless( { 'namespace' => { 'jmm' => { 'types' => {}, 'handles' => { 'shader' = +> { + 'ui' => { + 'synthetic' => '', + 'desc' => 'shader name', + 'order' => 0, + 'name' => 'shader' + }, + 'order' => 0, + 'type' => 'string', + 'default' => undef, + 'datatype' => 'string', + 'semantic' => '' + } } } }, 'name' => 'jmm', 'path' => 'jmm_mtl' }, 'material' ); ///////////////////////////////////////////////////////////// XML::Simple->new(XMLDecl=>1, NoSort=>1, KeepRoot=>1, NoAttr=>1, RootName=>ref($self) );
gives me this:
/////////////////////////////////////////////////////////////// <?xml version=\'1.0\' standalone=\'yes\'?> <material> <namespace> <types></types> <handles> <order>0</order> <ui> <synthetic></synthetic> <desc>shader name</desc> <order>0</order> <name>shader</name> </ui> <name>shader</name> <default></default> <type>string</type> <semantic></semantic> <datatype>string</datatype> </handles> <name>jmm</name> </namespace> <name>jmm</name> <path>jmm_mtl</path> </material> ///////////////////////////////////////////////////////////////////
Notice the placement of the singleton entry in both namespace hash and the handles hash namely 'jmm' and 'shader' repectively into a "name" tag. So when I load up the XML data:
/////////////////////////////////////////////////////////////////// my $xml = XML::Simple->new(XMLDecl=>1, NoSort=>1, KeepRoot=>1, NoAttr=>1, RootName=>"mtl" ); ///////////////////////////////////////////////////////////////////
I get this:
/////////////////////////////////////////////////////////////////// bless( { 'namespace' => { 'handles' => { 'ui' => { 'order' => '0', 'desc' => 'shader + name', 'name' => 'shader +' }, 'order' => '0', 'name' => 'shader', 'type' => 'string', 'datatype' => 'string' }, 'name' => 'jmm' }, 'name' => 'jmm', 'path' => 'jmm_mtl' }, 'material' ); ///////////////////////////////////////////////////////////////////
This does not happen if there is more than one key in either of the nested hashes. Two or more keys in the nexted hash returns the identical structure I had when I started. Have I found a bug? If not how do I force the module not to exhibit this behavior or must I accept this reality "as it is" ? Jean-Michel

In reply to XML::Simple nested hash bug? by jmmistrot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.