What’s the best way to discover all variables a Perl application has currently defined?
问题 I am looking for best, easiest way to do something like: $var1="value"; bunch of code..... **print allVariablesAndTheirValuesCurrentlyDefined;** 回答1: Package variables? Lexical variables? Package variables can be looked up via the symbol table. Try Devel::Symdump: #!/path/to/perl use Devel::Symdump; package example; $var = "value"; @var = ("value1", "value2"); %var = ("key1" => "value1", "key2" => "value2"); my $obj = Devel::Symdump->new('example'); print $obj->as_string(); Lexical variables