zigdon has asked for the wisdom of the Perl Monks concerning the following question:
Esteemed monks,
I'm trying new grounds, and decided I should really start using XML. Ok, so I read XML::Simple, and it really does seem simple enough. Until I ran into the following problem:
I have the following XML:
<config> <gallery> <template>admin.tmpl</template> <directory>..</directory> </gallery> <pictures> <picture> <Mtime>1039101693</Mtime> <Size>4096</Size> <Type>File</Type> <Name>picture.jpg</Name> </picture> <picture> <Mtime>1039036371</Mtime> <Size>38633</Size> <Type>File</Type> <Name>test.jpg</Name> </picture> ...
Now say I want to find the Mtime of 'test.jpg'. In the hashref returned by XML::Simple, it would be here:
${$ref->{pictures}->{picture}}[1]->{Mtime}
(or something similar). But that means that to get the information I have to know it's position in the array. Is there a way to find that position without looping over the whole array? I could defenitly do something like this:
$xmlref = grep { $_->{Name} eq 'test.jpg' } @{$ref->{pictures}->{pic +ture}};
But that seems wasteful. Is there any other way?
Thanks!
-- Dan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (z) Finding an XML element with XML::Simple
by mirod (Canon) on Dec 05, 2002 at 16:41 UTC | |
by grantm (Parson) on Dec 05, 2002 at 19:49 UTC |