http://qs1969.pair.com?node_id=11131461

PV66 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Community, Really hoping to get some perl-wisdom on this one, its my second day working on Perl today, and I'm just stuck with an issue that I can't seem to figure out.

Basically I have an XML

<root> <ref name="abc_sia_%version1.ref%"> <func envname = "test01" objectdir = "/home/pv66" base="default_771"/> </ref> </root>
I want to get the ref name's value, that is "abc_sia_%version1.ref%" as my hash key and the corresponding elements of the tag in a list. So I used Simple XML's function
my $xml = new XML::Simple; my $data = $xml->XMLin("/home/pv66", ForceArray => 1, KeyAttr => { ref + => "name"}); print Dumper ($data);
But this gives me
$VAR1 = { 'ref' => { 'abc_sia_%version1.ref' => { 'func' => [ { 'envname' => 'test01', 'objectdir' => '/home/pv66', 'base' => 'default_771' } ] } };
And this extra level of hierarchy (after ref) is undesired. I've read at some places that XML::Simple is not the preferred module, and XMLLib should be used, but I couldn't find any resources that drew a parallel to the ForceArray attribute of the XML in method. The desired hash should be:
$VAR1 = { 'abc_sia_%version1.ref' => { 'func' => [ { 'envname' => 'test01', 'objectdir' => '/home/pv66', 'base' => 'default_771' } ] } };
Any help pertaining to this would be appreciated.