Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: %main:: and my'd vars

by broquaint (Abbot)
on Jul 15, 2002 at 15:02 UTC ( [id://181802]=note: print w/replies, xml ) Need Help??


in reply to Re: %main:: and my'd vars
in thread %main:: and my'd vars

Here's a small example of how you might use PadWalker to look at the variables in the current lexical scope
use PadWalker qw(peek_my); use Data::Dumper; my $s = "a string"; { my @a = qw(an array); print Dumper( peek_my(0) ); } my %h = qw(a hash); print Dumper( peek_my(0) ); __output__ $VAR1 = { '@a' => [ 'an', 'array' ], '$s' => \'a string' }; $VAR1 = { '%h' => { 'a' => 'hash' }, '$s' => \'a string' };
Funky huh?
HTH

_________
broquaint

Replies are listed 'Best First'.
Re^3: %main:: and my'd vars
by abhay180 (Sexton) on May 11, 2023 at 20:06 UTC
    use PadWalker qw(peek_my); do "xyz"; #this file has many hashrefs defined foreach $item (keys %{peek_my(0)}) { print $item,"\n"; print $item if (ref $item eq ref {}); }
    I dont get any o/p . why is this so? Code in "xyz" file:
    $a1 = { 'p' => 1, 'q' => 2, }; $a2 = { 'p' => 1, 'q' => 2, };
      you didn't use my for your variables.

      update

      use v5.12.0; use warnings; use PadWalker qw/peek_my peek_our/; my $a1 = {}; our $a2 = {}; for my $space ( peek_my(0),peek_our(0) ){ for my $item (keys %{$space}) { say $item if (ref ${$space->{$item}} eq "HASH"); } }

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found