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

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

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

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

5条回答
  •  萌比男神i
    2020-12-30 11:36

    The global symbol table is %main::, so you can get global variables from there. However, each entry is a typeglob which can hold multiple values, e.g., $x, @x, %x, etc, so you need to check for each data type. You can find code that does this here. The comments on that page might help you find other solutions for non-global variables (like lexical variables declared with "my").

提交回复
热议问题