Building on the correction by Anonymous Monk above, the following code gives you a hash in which each entry has a vendorUniqueKey as the key and the corresponding name as the value:
#! perl use strict; use warnings; use Data::Dumper; use XML::Simple; my $xmldoc = XMLin("dsys.xml"); my $vendors = $xmldoc->{'Catalog'}->{'Vendors'}; my %vendors = %{ $vendors->{'Vendor'} }; my %unique_vendors; while (my ($outer_key, $outer_value) = each %vendors) { if (ref($outer_value) eq 'HASH') { my ($inner_key, $inner_value) = each %$outer_value; if ($inner_key eq 'vendorUniqueKey') { $unique_vendors{$inner_value} = $outer_key; } else { warn "Inner key is not 'vendorUniqueKey'"; } } else { warn "Outer value is not a hash reference"; } } print Dumper(\%unique_vendors);
Output:
$VAR1 = { 'BETASYS' => 'Beta Systems Software', 'BMC' => 'BMC Software', 'ALLENGRP' => 'Allen Systems', 'AONIX' => 'Aonix North America' };
HTH,
Athanasius <°(((>< contra mundum
In reply to Re: Help with attributes and XML::Simple
by Athanasius
in thread Help with attributes and XML::Simple
by Smaug
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |