Re: XML::Simple array size
- From: "Dave" <daveandniki@xxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 14:01:02 +0100
<robic0> wrote in message news:g5uno11r6901vv00tnpln9r35j3q4v3jfc@xxxxxxxxxx
> On Sat, 14 Feb 2004 17:58:08 -0500, Mark J Fenbers
> <Mark.Fenbers@xxxxxxxx> wrote:
>
>>In my sample XML file...
>>
>><main>
>> <level1>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> ...
>> </level1>
>></main>
>>
>>I have an variable number of level2 tags. Using XML::Simple, I can access
>>the
>>value of the 4th one by something like this:
>>
>> my $main = XMLin("myfile.xml");
>> print $main->{level1}->{level2}->[3]->{content};
>>
>>But I really want to know how many level2 records there are. I tried
>>variations
>>
> Hey isn't the "$main" name take already?
> New rule, you have to give more details than "I want to count all
> animals on Noah's ark". Noah didn't coun't them for a reason....
> Unless you positively know ahead of time the structure of the xml
> in question, you can't rely on xml::simple's output structure.
> I guess thats the other question.....
Answering the OP's question. If there are a variable number <level2>
my $element_count = @{ $main->{level1}->{level2} };
should do it (untested).
If there is only one level2 this will give an error unless you force
XML::Simple to make it an array.
.
- References:
- Re: XML::Simple array size
- From: robic0
- Re: XML::Simple array size
- Prev by Date: Re: Perl subtraction wierdness
- Next by Date: Re: evaluate sine series.
- Previous by thread: Re: XML::Simple array size
- Next by thread: Upgrade Perl5.8.7
- Index(es):
Relevant Pages
|