Trouble understanding data structure

P

Page

I have some XML that I read in and print out using Data::Dumper which
has helped me tremendously, but I'm struggling with some parts of it.

Here is the sample Dumper output:
$VAR1 = {
'detail' => [
{
'table' => [
{
'tr' => [
{
'td' => [
{
'content' => '2316692',
'form' => '$',
'm' => '1',
'type' => 'red'
},
' ',
' ',
' '
]
}
],
'tt' => [
'Daily'
],
etc...

The problem is when I try to loop through the table. Sometimes the
child is a tt and sometimes the child is a tr and in other cases it is
a th.

How do I check to see which one it is?
for (@{$struct->{detail}->[0]->{table}}) {
# I want to now loop through all the children but do different
stuff dependinging on whether the child is a tr, tt, or th.
}
 
B

Brian McCauley

Page said:
I have some XML that I read in and print out using Data::Dumper which
has helped me tremendously, but I'm struggling with some parts of it.

Here is the sample Dumper output:
$VAR1 = {
'detail' => [
{
'table' => [
{
'tr' => [
{
'td' => [
{
'content' => '2316692',
'form' => '$',
'm' => '1',
'type' => 'red'
},
' ',
' ',
' '
]
}
],
'tt' => [
'Daily'
],
etc...

I don't think you've cut-and-pasted that literally.
The problem is when I try to loop through the table. Sometimes the
child is a tt and sometimes the child is a tr and in other cases it is
a th.

How do I check to see which one it is?
for (@{$struct->{detail}->[0]->{table}}) {
# I want to now loop through all the children but do different
stuff dependinging on whether the child is a tr, tt, or th.
}

I think you have an array of single element hashes.

You can find the key value of a single element hash using:

my ($tag) = keys %$_; # Note the list context
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top