Hi, new to this forum...

I'm am trying to add an element to a hash of arrays, but can't quite figure out the correct syntax...The original data structure was created using XML::Simple()...

my $gxmlConfigObjt = new XML::Simple( forcearray => 1 ,keyattr => {} ,rootname => 'feedback' ); # OPEN : Open the file... # my $gxmlConfigDoc = $gxmlConfigObjt->XMLin( $gxmlConfigFile );

And looks like the following from Data::Dumper()...(p.s. I doctored the output to save on space) ...

.$gxmlConfigDoc = { . 'item' => [ . { 'zip-code' => ['03036'] . ,'city' => ['Chester'] . ,'name' => ['Adym S. Lincoln'] . ,'address' => ['123 Lane Road'] . ,'state' => ['NH'] . }, . { 'zip-code' => ['03103'] . ,'city' => ['Manchester'] . ,'name' => ['Joseph C. Lincoln'] . ,'address' => ['1050 Perimeter Road'] . ,'state' => ['NH'] . } . ] .};

I tried/wanted to use push, but that didn't work...Here's some failed attempts...

$gxmlConfigDoc{item}[++$#{gxmlConfigDoc{item}}] = { 'zip-code' => ['01880'], 'city' => ['Wakefield'], 'name' => ['Whatdb'], 'address' => ['20 Harvard Mill S +q'], 'state' => ['MA'] }; #$gxmlConfigDoc{item} = { 'item' => [ # { # 'zip-code' => ['01880'], # 'city' => ['Wakefield'], # 'name' => ['Whatdb'], # 'address' => ['20 Harvard Mill +Sq'], # 'state' => ['MA'] # } # ] # }; #push @{ $gxmlConfigDoc{item} }, # 'item' => [ # { # 'zip-code' => ['01880'], # 'city' => ['Wakefield'], # 'name' => ['Whatdb'], # 'address' => ['20 Harvard Mill Sq'], # 'state' => ['MA'] # } # ] #;

tia,
adym

In reply to Adding elements to hashes of arrays... by alincoln

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.