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

Dear Perl Monks,

I know about %::, which makes it easy to find out which package variables are defined. Is there an equivalent for lexical variables? I want to know which lexical variables are defined so I can then dump then in a string eval(), so performance is not much of an issue; however, walking the entire heap the way Devel::FindRef would be quite painful.

I know this is not the intended normal use of lexical variables. I accept what I'm trying to do isn't normal.

Thanks in advance, a cowardly novice

Replies are listed 'Best First'.
Re: %:: equivalent for my() variables?
by tobyink (Canon) on Jun 06, 2014 at 06:50 UTC

    Use PadWalker.

    perl -MData::Dumper -MPadWalker=peek_my -e'my $x = 1; my @y = 1..3; my + %z => (foo=>42); print Dumper(peek_my(0));'
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: %:: equivalent for my() variables?
by Anonymous Monk on Jun 06, 2014 at 03:01 UTC
Re: %:: equivalent for my() variables?
by locked_user sundialsvc4 (Abbot) on Jun 06, 2014 at 07:17 UTC
    I know this is not the intended normal use of lexical variables.  I accept what I'm trying to do isn't normal.

    Such choices usually lead to regret.   What are you trying to do?