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

Hi all, So, I'm pretty sure this is an issue (or just process of) with perl ptkdb debugger tool that I use, I wanted to see if anyone has experienced similar issue. The error message I get is like this: ptkdb - >>> exception catched Not a SCALAR reference at (eval 49) line 4.

and I believe this occurs from the following line of code

my %hash = (); my $h_ref = \%hash; if(exists $$h_ref{'try'}) {

I'm pretty sure my dereferencing of the hash reference is correct, and I think it's simply something catched by the ptkdb tool (happens when I do step by step using the tool). The script actually executes correctly without an error if run normally. I just wanted to see if perlmonks knew of this issue (if anyone uses ptkdb) and that I can safely simply ignore this. Thank you!! Happy Thanksgiving!!

Replies are listed 'Best First'.
Re: PTKDB - exception catched Not a SCALAR reference
by stevieb (Canon) on Nov 24, 2015 at 17:22 UTC

    That's not how to dereference a hash ref. You're trying to deref it as a scalar, which it isn't, and that's why it's throwing the error.

    I was wrong... $$href{try} does actually work. My bad :) I can't figure out why you're receiving that error with the code you've supplied though. Can you post more context?

    Dereference individual items with the -> deref operator:

    # hashref $h_ref->{try}; # arrayref $aref->[0]; # scalar $$scalar_ref;

    ...and to dereference entire structures:

    # hash my %hash = %$hash_ref; # array my @array = @$aref;

    If you need to dereference an entire list-type reference out of a nested structure, you need to use the circumfix operator:

    # hash my %hash = %{ $hash_ref->{inner_href} }; # array my @array = @{ $aref->[0] };

    A bit more complicated... extract one list-type variable out of a different list-type variable:

    # array from href my @array = @{ $href->{inner_array} }; # hash from array ref my %hash = %{ $array->[0] };
      That's not true. Have you tried running the OP code? The "ugly" syntax is possible, too:
      $$href{try}

      is the same as

      $href->{try}

      You can even write

      ${$href}{try}
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        No, I didn't unfortunately, but did after I posted my reply (sigh). I was far too quick to assume. Normally I don't do that.

      Well, this does not stop my script from executing, I think it's just an exception catched warning (or error) from PTKDB tool.... which gets printed out when I step through the code... there really isn't much to the code. I think i will just ignore that and move on....

      Maybe it doesn't like the "ugly" syntax.... maybe I should stop using that syntax.

      Thanks for the elaborate examples though :) I do use lots of those in my script, and actually had some bug involving the exact same example of the "more complicated" ones

      @{$$href{inner_array}}

      ^ is how my code looks like and had got it wrong initially... i think i should change my syntax style.

      Thanks!!