Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Print variable name/value for all program variables

by greengaroo (Hermit)
on Nov 08, 2012 at 14:35 UTC ( #1002914=note: print w/ replies, xml ) Need Help??


in reply to [SOLVED] - Print variable name/value for all program variables

After a quick Google search, I found this interesting thread on Stack Overflow: How can I list all variables that are in a given scope?

Take a look at this code, from the thread:

{ no strict 'refs'; foreach my $entry ( keys %main:: ) { print "$entry\n"; } }

Although, I don't think you can use this "as is", I think this is a good clue for what to look for.

Testing never proves the absence of faults, it only shows their presence.


Comment on Re: Print variable name/value for all program variables
Download Code
Replies are listed 'Best First'.
Re^2: Print variable name/value for all program variables
by Athanasius (Abbot) on Nov 08, 2012 at 14:56 UTC

    Yes. Include a package declaration at the head of your script, then you can get the names of the variables (and subroutines) as follows:

    0:51 >perl -E "package Foo; $x = 42; $y = 'fred'; sub command { print + 'Special command'; } say for sort keys %Foo::;" command x y 0:54 >

    Hope that helps,

    Athanasius <°(((><contra mundum

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2015-07-31 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls