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

I am using the debugger to look at a complicated data structure
The use of grep and map are very helpful to limit and find what I want
But then I want to dive in just to examine one of the Hash References returned from this grep command:

DB<63> x 1 grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes 0 HASH(0xe4db284) 1 HASH(0xe55199c) 2 HASH(0xdad56fc) 3 HASH(0xdf42dcc) 4 HASH(0xe0b0f3c) 5 HASH(0xde3a554) 6 HASH(0xdd0ba44) 7 HASH(0xdb3c934) 8 HASH(0xe169014) 9 HASH(0xdfd6564) 10 HASH(0xdc1accc) 11 HASH(0xdef3684) 12 HASH(0xe4265f4) 13 HASH(0xdd6d7f4)

But I was hoping there might be a builtin way to do this in the actual debugger.
Is there some way to pass the HASH(0xe3867b4) straight to the debugger x command?
I Looked at the wisdom posted in How to turn "HASH(0x1234567)" into a real HASH

so I tried this: which is what I think I learned from the wisdom that I did not fully follow:
but I get the method not found error

DB<70> $a=hex e3867b4 DB<71> x $a 0 238577588 DB<72> my $hash = bless(\(0+$a), "B::AV")->object_2svref; Can't locate object method "object_2svref" via package "B::AV" at (eva +l 50)[d:/Perl/lib/perl5db.pl:737] line 2.

Can anyone make any suggestions?

Replies are listed 'Best First'.
Re: examining HASH(0x1234567) in Debugger
by jcb (Parson) on Jan 02, 2020 at 00:31 UTC

    Try:

    x 1 (grep {$_->{CHIPS_PART_NAM­E}=~/gravity/i} @goodRefDes)[4]

    You may need to adjust the number in the final list element selector, since none of your hashrefs in the example match the one you asked about.

      Thanks for weighing in Everyone
      This answer gives me the way to do what I wanted...


      You are right, I had cut and pasted the wrong hashref for my final example
      What I was really looking for was a way to explore deep-down in the guts of just one of the grep results

      Putting the paren around the output of grep lets me index into the grep results
      and then I can even go deeper into the data structure from there

      <
      x 2 (grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes)[4] 0 HASH(0xe0b0f3c) 'CDS_LIB' => 'contactor' 'CDS_LMAN_SYM_OUTLINE' => '-150,1400,150,-1400' 'CDS_LOCATION' => 'SITE1_19' 'CDS_PART_NAME' => 'GRAVITY_DIL_DUT_56_DGV_CONTACTOR-56P-FULL-GRAVI +TY_DIL_DUT_56_DGV' 'CDS_PHYS_PART_NAME' => 'GRAVITY_DIL_DUT_56_DGV_CONTACTOR-56P-FULL- +GRAVITY_DIL_DUT_56_DGV' 'CDS_SEC' => 1 'CHIPS_PART_NAME' => 'GRAVITY_DIL_DUT_56_DGV' 'DCF_ID' => 'SITE1_19' 'DESCRIPTION' => 'DUT, DIL, DGV, 56-PIN' 'DESIGN_BLK_INFO' => HASH(0xe0ad774) 'HPATH_INFO_LIST' => ARRAY(0xe0b1944) 'LOCATION' => 'SITE1_19' 'PACK_TYPE' => 'CONTACTOR-56P-FULL' 'PART_NUMBER' => 'GRAVITY_DIL_DUT_56_DGV' 'PHYS_PAGE' => 1 'PIN_LIST' => ARRAY(0xe0b16d4) 'PROP_INFO' => HASH(0xe0b15e4) 'RAW_HPATH' => '@\\6632725_lib\\.\\6632725\\(sch_1):page72_i6@\\663 +2725_lib\\.locustsite(sch_1):page1_i2' 'ROT' => 0 'SEC' => 1 'VER' => 2 'XY' => '(-4850,2200)'
      and even:
      x 2 (grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes)[4]->{PIN_L +IST}[0] 0 HASH(0xe0b1b54) 'ALT_NAME' => 'SITE1_19.1' 'PIN_NAME' => '\\1\\' 'PN' => 1
Re: examining HASH(0x1234567) in Debugger
by LanX (Saint) on Jan 01, 2020 at 15:50 UTC
    >   DB<63>  x 1 grep { ...

    Couldn't find it documented with h x , but the 1 limits the output to the first level.

    Good to know! :)

    Update

    Demo

    DB<17> !1 @a = map +{$_=>[1..3]}, a ..d DB<18> x 1 @a 0 HASH(0xa7041080) 1 HASH(0xa70411c0) 2 HASH(0xa70413e0) 3 HASH(0xa6f048c0) DB<19> x 2 @a 0 HASH(0xa7041080) 'a' => ARRAY(0xa70098d0) 1 HASH(0xa70411c0) 'b' => ARRAY(0xa7027540) 2 HASH(0xa70413e0) 'c' => ARRAY(0xa7027860) 3 HASH(0xa6f048c0) 'd' => ARRAY(0xa7041b70) DB<20>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      I may have misunderstood your question.

      If you want to dive selectively into a particular sub-hash, why don't you just select that hash by name or index?

      DB<27> x 1 @a 0 HASH(0xa7041080) 1 HASH(0xa70411c0) 2 HASH(0xa70413e0) 3 HASH(0xa6f048c0) DB<28> x grep /080\)/,@a 0 HASH(0xa7041080) 'a' => ARRAY(0xa70098d0) 0 1 1 2 2 3 DB<29> x @a[1] 0 HASH(0xa70411c0) 'b' => ARRAY(0xa7027540) 0 1 1 2 2 3 DB<30>

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: examining HASH(0x1234567) in Debugger
by LanX (Saint) on Jan 01, 2020 at 15:37 UTC
    Are you sure your initial example is returning hash refs?

    I'm surprised because x dives into nested structures.

    Looks for me like you are only returning stringifications of hash refs instead.

    update

    Please ignore...

    I wasn't aware about the maxdepth option when using x ...

    from perldebug#Debugger-Commands

    • x [maxdepth] expr
    If the maxdepth is included, it must be a numeral N; the value is dumped only N levels deep, as if the dumpDepth option had been temporarily set to N.

    ... since the internal help doesn't show it

    DB<79> h x x expr Evals expression in list context, dumps the result.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: examining HASH(0x1234567) in Debugger
by hexcoder (Curate) on Jan 02, 2020 at 08:32 UTC
    Hi,

    if you have some terminal scroll back functionality in your debugger session, you could just set the first parameter to something greater 1 (depending on how deep you want to dive in)
    x 10 grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes
    or leave it out to get the full hierarchy:
    x grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes

    If you want to filter further either add one more grep expression,
    x grep {more filtering...} grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes
    or if the order of hash entries is meaningful, accessing the array by indexing is another option, eg. access the last entry.
    x (grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodRefDes)[-1]

    Hope that helps.
Re: examining HASH(0x1234567) in Debugger
by Marshall (Canon) on Jan 04, 2020 at 11:35 UTC
    From what I see, @goodRefDes is an array of references to hash...

    Is source code something like this? I'm not sure?:

    my @gravity_hashrefs = grep {$_->{CHIPS_PART_NAME}=~/gravity/i} @goodR +efDes;
    Why not add into the source code:
     use Data::Dumper; at the beginnging of the code?

    Then add
     print Dumper \@gravity_hashrefs;?

    It is possible to add extra statements into a grep{}.
    I think this would work....

    grep { if ($_->{CHIPS_PART_NAME}=~/gravity/i) { print Dumper $_; 1; } else { 0; } } @goodRefDes;
    I am unsure why there is so much fascination with the Debugger when it is so easy to add print statements into Perl and compile and run the result at rocket speed. I seldom need the debugger even when writing "raw" C.