Search code examples
apiperlhashresponse

How to read HASH(0x1fcb970) using perl?


I'm really lost with this, how can I read this response form an API HASH(0x1fcb970) using perl.

my @info= $connection->fetchrow();

When I try to print the data:

print @info 

is when I get the HASH.


Solution

  • Something is a hash reference but is being treated as a string. When you stringify a reference, you get something like "HASH(0x1fcb970)" instead of what you intended or expected. You see numbers that look like they may be a memory address, but those aren't useful to you.

    You might start by inspecting what you got:

    use Data::Dumper;
    
    print Dumper( \@info );
    

    If you see what you expect there, then it's on your side to treat the reference properly.

    If it's an error on the API side. Open a ticket with them and have them fix it.


    There was a major newspaper that had this happen to them in 1990s, as I recalled. All of their headlines were "HASH(0x...)" for a couple of hours. :)