perldarren has asked for the wisdom of the Perl Monks concerning the following question:
Here is my problem: I want the attribute host_grp_id="CL1-A-0" as a key so I execute:<overview execute_time="2012/08/30-10:38" xml_version="01-50-02" too +l_version="01-50-02" save_time="2012/08/30-10:37" dkc_type="RAID600" +micro_version="60-08-11-00/00" dkc_serial="17353" /> <host_grps number_of_ports="32"> <port port_id="CL1-A" number_of_host_grps="1"> <host_grp host_grp_name="1A-G00" host_grp_id="CL1-A-0"> <host_mode>LINUX</host_mode> </host_grp> </port> <port port_id="CL3-A" number_of_host_grps="1"> <host_grp host_grp_name="3A-G00" host_grp_id="CL3-A-0"> <host_mode>LINUX</host_mode> </host_grp> </port> ...
gives me this:my $ref = XMLin('host_grp.xml', KeyAttr => { host_grps => 'port', por +t => "port_id", host_grp => "host_grp_id" }, ForceArray => 'host_grp_ +id' );
But I don't want the 'ports' thrown into an array. If I drop ForceArray and do this instead:$VAR1 = { 'overview' => [ { 'xml_version' => '01-50-02', 'save_time' => '2012/08/30-10:37', 'tool_version' => '01-50-02', 'execute_time' => '2012/08/30-10:38', 'dkc_serial' => '17353', 'micro_version' => '60-08-11-00/00', 'dkc_type' => 'RAID600' } ], 'host_grps' => [ { 'port' => { 'CL2-A' => { 'host_grp' => { 'CL2-A-0 +' => { + 'host_mode' => [ + 'LINUX' + ], + 'host_grp_name' => '2A-G00' + } }, 'number_of_host_grps' +=> '1' }, 'CL6-B' => { 'host_grp' => { 'CL6-B-0 +' => { + 'host_mode' => [ + 'LINUX' + ], + 'host_grp_name' => '6B-G00' + }, 'CL6-B-1 +' => { + 'host_mode' => [ + 'LINUX' + ], + 'host_grp_name' => 'schiphol_srs_gold' + } }, 'number_of_host_grps' +=> '2' },
I then get the following:my $ref = XMLin('host_grp.xml', KeyAttr => { host_grps => 'port', por +t => "port_id", host_grp => "host_grp_id" } );
Notice that since CL2-A has only one 'host_grp' the host_grp_id which I would like to be a key is folded up making the key unavailable for query in my hash.$VAR1 = { 'overview' => { 'xml_version' => '01-50-02', 'save_time' => '2012/08/30-10:37', 'tool_version' => '01-50-02', 'execute_time' => '2012/08/30-10:38', 'dkc_serial' => '17353', 'micro_version' => '60-08-11-00/00', 'dkc_type' => 'RAID600' }, 'host_grps' => { 'port' => { 'CL2-A' => { 'host_grp' => { 'host_mode +' => 'LINUX', 'host_grp_ +id' => 'CL2-A-0', 'host_grp_ +name' => '2A-G00' }, 'number_of_host_grps' => + '1' }, 'CL6-B' => { 'host_grp' => { 'CL6-B-0' +=> { + 'host_mode' => 'LINUX', + 'host_grp_name' => '6B-G00' + }, 'CL6-B-1' +=> { + 'host_mode' => 'LINUX', + 'host_grp_name' => 'schiphol_srs_gold' + } }, 'number_of_host_grps' => + '2' },
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Simple - Answered !
by Jenda (Abbot) on Aug 31, 2012 at 11:53 UTC |