-4

I have a Perl hash and I dont know what its content looks like.

When I print out its keys and values (check attached hash loop picture) I get for values what looks like a string that contains another hash for each value (check output of hash loop picture).

How can I print out the keys and values for these hashes?

output of hash loop

hash loop2

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • 2
    Possible duplicate of [How to print complex data(Array of Hash) structure in perl](https://stackoverflow.com/questions/22165108/how-to-print-complex-dataarray-of-hash-structure-in-perl) – buff Jun 28 '18 at 12:37
  • thanks for the answer, doesnt look like the same thing to me since i have what looks like a hash of strings that contain hash references, i simply want to know how i can create from a string like "HASH(0x5602d430ecd8)" a new hash and print out its keys and values – VBAidontgetitDUDE Jun 28 '18 at 12:42
  • if you do `use Data::Dumper; print Dumper(\%your_hash);`, you'll see what is contained in your "hash of strings". – buff Jun 28 '18 at 12:44
  • 3
    Please include the code as text in your post, not a screenshot, and please provide an [MCVE](https://stackoverflow.com/help/mcve) that we can run to reproduce the issue. – haukex Jun 29 '18 at 08:38
  • 1
    I will never understand why people think it's useful to images that contain code! – Dave Cross Jun 29 '18 at 11:47

1 Answers1

0

Your getVarHash() method return a hash reference. And when you dereference the hash and look at the contents, you see that it contains references to other hashes.

Actually, those second level hashes aren't just ordinary hash references - they are blessed hashes. You can see that from the Variable= in front of the hash reference in your output. A "blessed hash" is an object. So what you have here are a number of objects of the "Variable". That doesn't seem to be a standard Perl class so, hopefully, you'll have documentation somewhere on how to use this class.

You should really treat objects as black boxes and use the published interface to access the data inside them. But you can treat them as normal hash references if necessary.

The easiest way to see what is in a complex data structure like this, is to use something like Data::Dumper to display the structure.

use feature 'say';
use Data::Dumper;

say Dumper $vars->getVarHash();

Perl has plenty of good documentation on how to understand and manipulate complex data structures. I recommend taking a look at the Data Structures Cookbook.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97