in reply to Re^2: Adding row in a hash Help!!
in thread Adding row in a hash Help!!

And what does, "does not work" mean this time?

I got a pretty clear error message when running your script:

Global symbol "$data" requires explicit package name ...

Which led me to this line:

push @data, $data->[0]{'xml_api_reply'}{'weather'}{'report_date'} = {' +-data' => $today };

Which I changed to this:

push @data, $weather_data->[0]{'xml_api_reply'}{'weather'}{'report_dat +e'} = {'-data' => $today };

Now it runs without errors.

Replies are listed 'Best First'.
Re^4: Adding row in a hash Help!!
by Anonymous Monk on Aug 20, 2012 at 02:53 UTC
    It runs, but look at the extra line added to end end of the file:
    ... $VAR1->[1] = $VAR1->[0]{'xml_api_reply'}{'weather'}{'report_date'};

      Ah, ok. Try these changes:

      # no need for this loop: # for my $w_data (@$weather_data) { # push @data, $w_data; # } # Now add 'report_date' key and its value at the appropriate level. #push @data, $weather_data->[0]{'xml_api_reply'}{'weather'}{'report_da +te'} = { '-data' => $today #}; push @{$weather_data->[0]{'xml_api_reply'}{'weather'}{'report_date'}}, + { '-data' => $today }; # print Dumper(\@data); print Dumper(\$weather_data);
Re^4: Adding row in a hash Help!!
by Anonymous Monk on Aug 20, 2012 at 04:03 UTC
    Here is the answer:
    $data[0]{'xml_api_reply'}{'weather'}{'report_date'} = {'-data' => $tod +ay };

    No need to use push!