Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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.

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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988378]
marto wonders what fresh hell the firefox update has brought, apart from maxing out CPUs
1nickt was looking into Firefox Extended Support releases yesterday. You don't have to go with the updates!
[erix]: wonderfully red sun here
[LanX]: FF has become a source of instability :(
[1nickt]: erix not so wonderful for the lungs :-(
[erix]: the stuff is pretty high up as I understand it; I have not felt any effect on lungs/breathing

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-10-17 12:32 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (230 votes). Check out past polls.