vbrtrmn has asked for the wisdom of the Perl Monks concerning the following question:
Good evening my fine monks, please offer me some kind advice for my sometimes foolish questions.
I'm working with XML::Simple and Data::Dumper.
Both seem to work great, I can pass my xml file and I can get the dump w/ no problem.
My question is: "How can I count the number of elements in LOGENTRY, if the data is stored in a scalar rather than a hash?"
In my simplified version I can obviously tell that I have 4 elements, but in a more complex one I have more, say 80 or 150. I'd use a subroutime to print the 129th element if it exists (or whatever).
simplified script
#!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $file = "test.xml"; my $config = XMLin($file); print Dumper($config); exit;
simplified output
$VAR1 = { 'LOGENTRY' => [ { 'DATE' => 'Date 0', 'MEMO' => 'Memo 0', 'TITLE' => 'Test 0' }, { 'DATE' => 'Date 1', 'MEMO' => 'Memo 1', 'TITLE' => 'Text 1' }, { 'DATE' => 'Date 2', 'MEMO' => 'Memo 2', 'TITLE' => 'Text 2' }, { 'DATE' => 'Date 3', 'MEMO' => 'Memo 3', 'TITLE' => 'Text 3' } ] };
thanks
(not even close to a saint) paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting Elements output from Data::Dumper
by LTjake (Prior) on Nov 09, 2002 at 02:02 UTC | |
by vbrtrmn (Pilgrim) on Nov 09, 2002 at 17:07 UTC | |
|
Re: Counting Elements output from Data::Dumper
by robartes (Priest) on Nov 09, 2002 at 12:50 UTC | |
by vbrtrmn (Pilgrim) on Nov 09, 2002 at 17:03 UTC | |
by robartes (Priest) on Nov 09, 2002 at 19:01 UTC |