What’s the best way to discover all variables a Perl application has currently defined?

前端 未结 5 2027
太阳男子
太阳男子 2020-12-30 11:01

I am looking for best, easiest way to do something like:

$var1=\"value\";
bunch of code.....
**print allVariablesAndTheirValuesCurrentlyDefined;**

5条回答
  •  情深已故
    2020-12-30 11:19

    Nathan's answer is part of the story -- unfortunately, the rest of the story is that lexical variables aren't listed in %main:: or anywhere else (at least anywhere accessible from Perl -- it's probably possible to write some hairy XS code that digs this information out of Perl's C-level internals).

    Lexical variables are what you would normally use for "ordinary local" variables. They are declared like:

    my $x;
    

提交回复
热议问题