in reply to Multidimensional Hash losts entrys
@complete{@arr_a} = ...;
It's not clear what exactly you want to assign, though. Does the following work for you?
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use XML::LibXML; my $xml = 'XML::LibXML'->load_xml( string => <<'__XML__'); <root> <node a="a b" b="A B" c="AA BB"/> <node a="1" b="2" c="3"/> <node a="X Y Z" b="x y z" c="xx yy zz"/> </root> __XML__ my %complete; for my $node ($xml->documentElement->findnodes('*')) { my ($a, $b, $c) = map $node->getAttribute($_), 'a', 'b', 'c'; if (3 == grep defined, $a, $b, $c) { my @arr_a = split (/ /, $a); my @arr_b = split (/ /, $b); my @arr_c = split (/ /, $c); @complete{@arr_a} = map [ shift @arr_b, shift @arr_c ], @arr_a +; } else { print "Warning! \n"; } } print Dumper \%complete;
Update: Note that I populate the hash only if all the attributes are defined. In your case, the @arr_X arrays were global, so the hash was repopulated again with the old values. (I use strict and warnings, why don't you?)
The map expression might look a bit complex for an untrained eye. It just picks one element from b and c for each element of a.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Multidimensional Hash losts entrys
by Anonymous Monk on Aug 14, 2014 at 05:23 UTC |