Dear community, I have a problem when I try to count the items in a hash variable which was created by XML::Simple from a xml file.

My xml looks like:
<?xml version="1.0" encoding="UTF-8"?> <config> <log> <destination>e1@mail.de</destination> <destination>e2@mail.de</destination> <destination>e3@mail.de</destination> </log> <item> <id>0</id> <filename>file1</filename> <extension>txt</extension> </item> <item> <id>1</id> <filename>file2</filename> <extension>txt</extension> </item> </config>

if i try to count the <destination> items with scalar (keys $config->{log}->{destination}); AND there are more then 1 destinations, then it works fine. But if I reduce it in the xml to just one email address it throws an error:
Type of argument to keys on reference must be unblessed hashref or arr +ayref at test.pl line 13.
___________________

The second problem which I have is to count the <item> nodes. If there are more then one nodes it works fine, like by <destination>. But if there is just one <item> node, it counts the nodes in this <item>. In my case it is 3 (<id>,<filename>,<extension>).

The way I translated my xml file in Hash is:
use XML::Simple qw(:strict); $config = XMLin('config.xml', KeyAttr => { server => 'name' }, ForceAr +ray => [ 'server', 'address' ]);

I would be glad, if someone could help me, because I didn't find anything while googling...

thanks a lot!
Dimitri

p.s
by some reason the word array splits here automatically in "ar+
ray"

In reply to Problem with counting the nodes in a hash created by XML::Simple from a XML file. by turbodizik

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.