Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Trouble understanding data structure

Reply
Thread Tools

Trouble understanding data structure

 
 
Page
Guest
Posts: n/a
 
      10-21-2004
I have some XML that I read in and print out using Data:umper 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.
}
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      10-23-2004
Page wrote:

> I have some XML that I read in and print out using Data:umper 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple structure and copying data to pointer of the same structure A C++ 27 04-16-2011 11:07 PM
Trouble accessing data with pointer to structure drhowarddrfine C Programming 2 12-09-2007 04:30 AM
Trouble understanding StateServer!! Ric Pullen ASP .Net 1 07-23-2004 08:17 AM
Trouble understanding pointer to a const array. Rob C++ 1 03-07-2004 10:35 PM
trouble understanding None Jakle Python 9 11-13-2003 04:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57