Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'll start off by say thanks to Ben, I got the last problem fixed. Now the next:
So I inhereted a script k.pl that runs on win32 using Tk as a GUI. I've been trying to automate several tasks in the app as they are very tedious and require huge amounts of user interaction. It's worth noting k.pl references several .pms. My problem now is that I'm printing several variable so I know what I need to pass to the various .pms and I got the following:

K::DB::Item=HASH(0x5897d64)

This was a valus that I got from printing the var $obj.


$obj is passed from a selection menu where the user is asked to select an item. K::DB:Item is think references a cache to the local MySQL database that the apps uses. I have a folder called K::DB and an item.pm in Perl/Site/Lib.

I guess what I'd like to know if now do I print the value behind the HASH, is there one. I've read that I need to put it into an array to print it? Is that right how do I do that?

Sorry for the dumb questions, I'm still learning. -Mark

20030818 Edit by jeffa: Changed title from 'Automating help '

  • Comment on Printing the keys/values of a blessed hash?

Replies are listed 'Best First'.
Re: Printing the keys/values of a blessed hash?
by Kanji (Parson) on Aug 13, 2003 at 23:00 UTC

    You can do a for ( my($k,$v) = each %$obj ) { ... } to give you a basic idea of what's inside the hash, but I personally use Data::Dumper in these types of situations as it will automatically recurse multi-dimensional arrays, hashes, etc.

    use Data::Dumper; print Data::Dumper->Dump([ $obj ],[qw( obj )]);

        --k.


Re: Printing the keys/values of a blessed hash?
by vek (Prior) on Aug 14, 2003 at 01:15 UTC

    I've got to agree with Kanji, Data::Dumper is an invaluable tool when debugging code. A simple print Dumper $obj; should give you all the info you need.

    -- vek --