Getting a list of all current variables in a Perl program

Discussion in 'Perl Misc' started by James E Keenan, Nov 15, 2005.

  1. From a 1997 posting by Randal L Schwartz on this list, I got the
    following code as a way to get a list of all (or most ??) identifiers in
    a program at a given point.

    print "\n\n" .
    Dumper ({
    map {
    (defined $$_ ? ("\$$_" => $$_) : ()),
    (defined @$_ ? ("\@$_" => \@$_) : ()),
    (defined %$_ ? ("\%$_" => \%$_) : ()),
    } sort keys %{__PACKAGE__."::"}
    });

    1. Are there any better ways to approach this problem?
    2. In addition to package variables, how can I get a list of the
    lexical variables declared at a given point in a program? (I think this
    means the content of the scratchpad(s)?)

    TIA

    Jim Keenan
     
    James E Keenan, Nov 15, 2005
    #1
    1. Advertising

  2. James E Keenan wrote:
    > From a 1997 posting by Randal L Schwartz on this list, I got the
    > following code as a way to get a list of all (or most ??) identifiers in
    > a program at a given point.
    >
    > print "\n\n" .
    > Dumper ({
    > map {
    > (defined $$_ ? ("\$$_" => $$_) : ()),
    > (defined @$_ ? ("\@$_" => \@$_) : ()),
    > (defined %$_ ? ("\%$_" => \%$_) : ()),
    > } sort keys %{__PACKAGE__."::"}
    > });
    >
    > 1. Are there any better ways to approach this problem?
    > 2. In addition to package variables, how can I get a list of the
    > lexical variables declared at a given point in a program? (I think this
    > means the content of the scratchpad(s)?)


    perldoc B::Xref
    perldoc B::Showlex


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Nov 15, 2005
    #2
    1. Advertising

  3. John W. Krahn wrote:

    > James E Keenan wrote:
    >
    >>
    >>1. Are there any better ways to approach this problem?
    >>2. In addition to package variables, how can I get a list of the
    >>lexical variables declared at a given point in a program? (I think this
    >>means the content of the scratchpad(s)?)

    >
    >
    > perldoc B::Xref
    > perldoc B::Showlex
    >

    Those look helpful and I will check them out today. Thanks, John!

    jimk
     
    James E Keenan, Nov 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    560
  2. simon

    print all current variables

    simon, May 3, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    116
    Bob Walton
    May 3, 2005
  3. Fei Liu
    Replies:
    2
    Views:
    2,101
  4. Fei Liu
    Replies:
    2
    Views:
    442
    -berlin.de
    Mar 28, 2007
  5. Jack
    Replies:
    3
    Views:
    672
    Tad J McClellan
    Dec 22, 2008
Loading...

Share This Page