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

print $sqlexecinfo; shows 1677721807/20/2017 00:03:38 while print $sidstat{$instsid}; shows HASH(0x2017b98) why is the difference?

open(SQLPLUS,"$CMD|") or die "Could not start SQLPLUS"; while (<SQLPLUS>) { chomp; my ($instsid,$sqlexecinfo)=split '=>'; $sidstat{$instsid}{SQLEXECINFO}=$sqlexecinfo; print $sqlexecinfo; print $sidstat{$instsid}; } debug(scalar(keys %sidstat)." session state recorded.\n"); return \%sidstat;

Replies are listed 'Best First'.
Re: Value of a key in hash in hex
by huck (Prior) on Jul 20, 2017 at 07:15 UTC

    $sidstat{$instsid} contains a hash reference, a pointer to a hash where the key SQLEXECINFO contains 1677721807/20/2017 00:03:38

      I have tested below code and it doesn't show the reference, I am just trying to figure out what is the difference between this and what I have pasted earlier

      #!/usr/bin/perl # create our perl hash $prices{"pizza"} = 12.00; $prices{"coke"} = 1.25; $prices{"sandwich"} = 3.00; #-------------------------------------------------- # option 1: # print the hash key and value using a foreach loop #-------------------------------------------------- foreach $key (keys %prices) { print "$key costs $prices{$key}\n"; }

        Illustrative example:

        use strict; use warnings; use Ref::Util 'is_hashref'; use Test::More tests => 2; my %hash; $hash{foo} = 1; $hash{bar} = { baz => 'quux' }; ok is_hashref ($hash{bar}); ok not is_hashref ($hash{foo});

        See perlreftut and perldsc.

        Put another way, the value of the hash element  $prices{"pizza"} is a simple scalar: 12.00. The value of the hash element  $sidstat{$instsid} pasted earlier was a hash reference, and print printed the stringization of such a reference: something like HASH(0x2017b98).

        Consider an example:

        c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dumper; ;; my %hash; ;; $hash{'pizza'} = 12; $hash{'ref_to_hash'} = { 'one' => 'uno', 'two' => 'dos', }; ;; for my $hash_key (keys %hash) { print qq{'$hash{$hash_key}'}; print Dumper $hash{$hash_key}; } " '12' $VAR1 = 12; 'HASH(0x185b68)' $VAR1 = { 'one' => 'uno', 'two' => 'dos' };


        Give a man a fish:  <%-{-{-{-<

Re: Value of a key in hash in hex
by AnomalousMonk (Archbishop) on Jul 20, 2017 at 07:34 UTC

    One way to see (print) the contents (or "referent") of a reference is with the core module Data::Dumper:
        use Data::Dumper;
        ...
        print Dumper $sidstat{$instsid};
    (See also Data::Dump, which I like a little better, but which isn't core.)

    Update: See also the Perl Data Structures Cookbook and maybe also perllol for more info on dealing with complex data structures in Perl.


    Give a man a fish:  <%-{-{-{-<