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


In reply to Counting Elements output from Data::Dumper by vbrtrmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.