YAHP - Ref to a hash via xml::simple prob.

I

Ian Pellew

Hi all;

Yet another array/hash problem.

From this Google list this is a common problem that the Perlphiliacs
tell
us to perldoc whatever,
BUT
I am trying to get to grips with a fragment of an XMLin structure
which dumps to :-
{'Others...',
'our_tags' => { <=== $p
'idx_serno' => '10001',
'set' => [ <--- $$m
{ 'dscn' => 'Development set',
'serno' => [
{ 'value' => 'General Header',
'sdate' => '0310251502',
'name' => 'ph_',
'content' => '10003'
},
{ 'value' => 'Devs page footer',
'sdate' => '0310251502',
'name' => 'pt_',
'content' => '10004'
}
],
'content' => 1 <+++ Want to select set on this.
},
{ 'dscn' => 'Testers set',
'serno' => [
{ 'value' => 'Testers oage Header',
'sdate' => '0310251502',
'name' => 'ph_',
'content' => '10076'
},
{ 'value' => 'test footer',
'sdate' => '0310251502',
'name' => 'pt_',
'content' => '10104'
}
],
'content' => '2' <+++ Or this
}
]
}
};

I think I am right in saying this is a
our_tag=Hash # Ignoring idx_serno
Set=Array of Hashes
Serno=Array of Hashes

When I crack the ability to choose the key, values set from
{set->content=>$users_set}
then the rest of my problems will become clearer.

If I make {set} a hash by having only one set I have no problems
and can work out what I want, but the array Ummmm.

I am not keen to change XMLin as I have several other child tags of
'our_tags' all
running OK as these are all Hashes, besides, cracking this will give a
deeper insight
to a gang of hashes array mixers. Bit like being at a wild party.

Code fragments:-
my $p = XMLin(undef, keyattr=>[], forcearray=>0, normalisespace=>2);
my $m = \%$p->{our_tags}->{set};

Dumping $m shows both set->contents, but
Dumping $m->{set} shows
$VAR1 = { # HASH
'dscn' => 'Testers set',
'serno' => [ # Array
{ 'value' => 'Testers oage Header',
'sdate' => '0310251502',
'name' => 'ph_',
'content' => '10003' },
{ 'value' => 'test footer',
'sdate' => '0310251502',
'name' => 'pt_',
'content' => '10004' } ],
'content' => '2'};

Which is the second {set}, Only to be expected as this is probaly the
array
(list) thats in the Dumper buffer.

print ref($$m) . "\n"; # yeilds an ARRAY

How do I get something like:-
my $ls = $$m->{set}->???????? to give a reference to the array for set
1.

By tweeking XMLin $m drops nicely to
my $m = \%$p->{our_tags}->{set}->{1}->{serno}->{ph_}->{value}; #
Cheating.

Regards
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top