Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Adding row in a hash Help!!

by hbm (Hermit)
on Aug 20, 2012 at 02:46 UTC ( #988378=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^3: Adding row in a hash Help!!
Select or Download Code
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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-08-30 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls