Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Perl 5.8 to 5.16 and HASH error

by ig (Vicar)
on Sep 10, 2012 at 23:52 UTC ( #992874=note: print w/replies, xml ) Need Help??

in reply to Perl 5.8 to 5.16 and HASH error

When I am dealing with non-trivial data structures and when variables seem not to have the values I expect or need, I often use Data::Dumper to print the variables and see what I am dealing with. I might print to a log file but often find it sufficient to terminate the program with something like:

use Data::Dumper; ... die Dumper($Xml); foreach $key (keys %{$Xml->{data}}){ $sql1.="`$key`,";$sql2.="`$key`=?,";$sql3.='?,'; }

You know that either $Xml or $Xml->{data} is not a hash reference, from the error message. I would first want to know what it is. Then I would decide whether to change the preceding code to set it to what the following code requires, or change the following code to handle what it is.

Replies are listed 'Best First'.
Re^2: Perl 5.8 to 5.16 and HASH error
by robsgoingmad (Initiate) on Sep 12, 2012 at 08:15 UTC


    Dumper data below. Hope it helps

    Thanks for your help


      From your Dumper output you can see that $Xml->{data} is a reference to an array, not a hash.

      You can either change your code to produce the hash reference as it did before or change your code to work with the array as you are getting now. Which will be easier for you I can't say, having seen so little of your code.

      I would look carefully to see why the second hash in the array appears: the one with a single key 'XxX'. That key looks a little odd to me. Perhaps someone added some 'test' data to the input?

      One option would be to ignore the second and any other hashes that might appear in the array and process only the first one. This would be an easy next step at least, and you could always make further changes later.

      To process the first hash, you can change your loop to something like:

      foreach $key (keys %{$Xml->{data}->[0]}){ $sql1.="`$key`,";$sql2.="`$key`=?,";$sql3.='?,'; }


        I am going to go away and check the data. Thanks for all the useful help. The XxX is ok, but I need to investigate myself its exact purpose.

        Back in touch when I have checked

        Have a good weekend



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992874]
[Corion]: If all else fails, Spreadsheet::XLSX should be "installable" by manually copying the files, provided that the prerequisites are met
[thezip]: It fails in the "formatted 2-digit numeric" tests
[thezip]: Okay Corion, that's what I wanted to hear. Thanks!
[Corion]: Oh, a test failure... Just force-install it then? --force and potentially --notest to skip the tests alltogether ?
[ambrus]: thezip: is Activestate Perl usable for your scenario instead?
[MidLifeXis]: Yeah, --notest is good, not sure I would do --force.
[thezip]: It fails 2/10 tests in that group. What are the ramifications if I force it? What should I look for for?
[thezip]: I've migrated from ActiveState to Strawberry. No going back...
[thezip]: I'll try the --notest arg first when I get back from meetings (after lunch).
[thezip]: Thanks guys for your comments! :-)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2017-03-23 17:18 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (290 votes). Check out past polls.