user1847362
user1847362

Reputation: 41

XML::Dumper using wrong hash reference in output

I'm trying to serialize following data structure using XML::Dumper

'options_settings' => {
  'telnet.distinct.enable' => {
    'text' => 'Option telnet.distinct.enable needs to be set to \'on\' as of
 workaround for Bug 476803',
    'severity' => '7'
   }
 },
'EOS_details' => {
  '338' => bless( {
    'info' => '<a href="https://support.netapp.com/info/communications/ECMP1110462.html " target="_blank">  CPC-0705-02 </a>',
    'count' => '48',
    'ASUP_id' => 'AE20121117202086',
    'part' => 'ESH2 - X5511A-RC, X5511-RC-C',
    'category' => 'I/O Module',
    'EOS_date' => '06/02/2013',
    'severity' => '8'
   }, 'EOSObject' ),

The problem is that when I parse it into xml with XML:Dumper it uses the same memory address for 2 separate hash references:

  <item key="338">
   <hashref blessed_package="EOSObject" memory_address="0x295b5758">
    <item key="ASUP_id">AE20121117165273</item>
    <item key="EOS_date">06/02/2013</item>
    <item key="category">I/O Module</item>
    <item key="count">48</item>
    <item key="info">&lt;a href=&quot;https://support.netapp.com/info/communications/ECMP1110462.html &quot; target=&quot;_blank&quot;&gt;  CPC-0705-02 &lt;/a&gt;</item>
    <item key="part">ESH2 - X5511A-RC, X5511-RC-C</item>
    <item key="severity">8</item>
   </hashref>
  </item>
 </hashref>
<item key="options_settings">
 <hashref memory_address="0x295b5320">
  <item key="telnet.distinct.enable">
   <hashref memory_address="0x295b5758">
   </hashref>
  </item>
 </hashref>
</item>

Note the memory_address="0x295b5758".

So when reading back from file the option_settings hash reference points to EOS object :/

Is that a bug in XML::Dumper or I'm doing something wrong? Using the latest XML::Dumper 0.81

P.S. I tried to reproduce it outside of the main script and it works. Still I'm not able to understand how come the data got broken in the main script. This is the code where XML::Dumper is used:

    DEBUG("Before serialization: " . Data::Dumper::Dumper($result));
    my $dump = new XML::Dumper;
    my $dump_test = new XML::Dumper;
    my $test_xml = $dump_test->pl2xml ($result);
    DEBUG("After serialization in memory: " . Data::Dumper::Dumper($test_xml));
    $dump->pl2xml( $result, $filename );

Result is printed out properly. "options_settings" are separate entries. In $test_xml it's already mixed up with EOS_details

Upvotes: 4

Views: 234

Answers (1)

ddoxey
ddoxey

Reputation: 2063

I'm trying to replicate your issue without any success.

#!/usr/bin/perl -Tw

use strict;
use warnings;
use XML::Dumper;

my $eos = bless {
    'info'     => '<a href="https://support.netapp.com/info/communications/ECMP1110462.html " target="_blank">  CPC-0705-02 </a>',
    'count'    => '48',
    'ASUP_id'  => 'AE20121117202086',
    'part'     => 'ESH2 - X5511A-RC, X5511-RC-C',
    'category' => 'I/O Module',
    'EOS_date' => '06/02/2013',
    'severity' => '8'
    }, 'EOSObject';

my %data = (
    'options_settings' => {
        'telnet.distinct.enable' => {
            'text'     => 'Option telnet.distinct.enable needs to be set to \'on\' as of
 workaround for Bug 476803',
            'severity' => '7'
        }
    },
    'EOS_details' => { 338 => $eos }
);

print pl2xml( \%data );

The output of my program:

<perldata>
 <hashref memory_address="0x253fb18">
  <item key="EOS_details">
   <hashref memory_address="0x2517e08">
    <item key="338">
     <hashref blessed_package="EOSObject" memory_address="0x24f9998">
      <item key="ASUP_id">AE20121117202086</item>
      <item key="EOS_date">06/02/2013</item>
      <item key="category">I/O Module</item>
      <item key="count">48</item>
      <item key="info">&lt;a href=&quot;https://support.netapp.com/info/communications/ECMP1110462.html &quot; target=&quot;_blank&quot;&gt;  CPC-0705-02 &lt;/a&gt;</item>
      <item key="part">ESH2 - X5511A-RC, X5511-RC-C</item>
      <item key="severity">8</item>
     </hashref>
    </item>
   </hashref>
  </item>
  <item key="options_settings">
   <hashref memory_address="0x2517688">
    <item key="telnet.distinct.enable">
     <hashref memory_address="0x2517598">
      <item key="severity">7</item>
      <item key="text">Option telnet.distinct.enable needs to be set to &apos;on&apos; as of
 workaround for Bug 476803</item>
     </hashref>
    </item>
   </hashref>
  </item>
 </hashref>
</perldata>

I'm inclined to think there's something off with your program. :(

Upvotes: 3

Related Questions