2012-11-23 4 views
4
내가 XML을 사용하여 다음과 같은 데이터 구조를 직렬화하기 위해 노력하고있어

에 잘못된 해시 참조를 사용 :: 덤퍼XML은 :: 덤퍼 출력

'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'), 

는 문제가 있음 : 덤퍼 그것은 사용 2 개의 분리 된 해시 참조 대해 동일한 메모리 어드레스 = "0x295b5758"

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

참고 memory_address. 다시 파일에서 읽을 때

는 그래서 option_settings은 EOS 개체에 참조 점을 해시 :/

는 XML에서이 문제를 :: 덤퍼 아니면 내가 뭔가 잘못하고 있어요인가요? 최신 XML :: Dumper 사용하기 0.81

P.S. 메인 스크립트 외부에서 그것을 재현하려고 시도했지만 작동합니다. 여전히 주 스크립트에서 데이터가 어떻게 손상되었는지 이해할 수 없습니다.

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

결과가 제대로 인쇄됩니다 : 이 XML :: 덤퍼를 사용하는 코드입니다. "options_settings"는 별도의 항목입니다. $ test_xml에서 이미 EOS_details와 섞여 있습니다.

답변

3

아무 문제없이 문제를 재현하려고합니다.

#!/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); 

내 프로그램의 출력 :

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

내가 당신의 프로그램에 전원을 뭔가가 있다고 생각하는 경향이 있어요. :

+0

나는 더 큰 데이터 구조의 일부이다. 내가 사용하는 주 코드의 바깥에서 그것을 재현하려고 시도한다. – user1847362

+0

. 내가 별도의 스크립트로하면, 그것은 작동한다 :/나머지 코드에 문제가있는 것 같다. ... – user1847362

+0

@ user1847362 문제의 원인을 찾았습니까? – ddoxey