How can I list all variables that are in a given scope?

后端 未结 4 1228
半阙折子戏
半阙折子戏 2020-12-08 10:05

I know I can list all of the package and lexcial variables in a given scope using Padwalker\'s peek_our and peek_my, but how can I get the names an

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 10:29

    Thanks, Chas, very useful code. As a note for future users of your code with perl > 5.12:

    I was using it in in my pdl2 .perldlrc to find out lexical variables (like the 'y' command in the debugger) and I had this warning:

    load_rcfile: loading

    /homes/pmg/.perldlrc defined(%hash) is deprecated at (eval 254) line 36.

        (Maybe you should just omit the defined()?)
    

    From perldoc -f defined

    Use of defined on aggregates (hashes and arrays) is deprecated. It used to report whether memory for that aggregate had ever been allocated. This behavior may disappear in future versions of Perl. You should instead use a simple test for size:

    >     if (@an_array) { print "has array elements\n" }
    >     if (%a_hash) { print "has hash members\n" }
    

    What I don't understand is why it only complained with the defined hash and not also with the array?

提交回复
热议问题