obonaventure has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking to have the ability to dump all currently defined variables in a perl script by calling a function or subroutine. I know I could write a subroutine to list the variables I was interested in but I thought that maybe there was a way to do it automatically. It would be nice to be able to reuse the code in other script without needing to modify it everytime a variable is added or deleted.

Replies are listed 'Best First'.
Re: List all defined variables
by kyle (Abbot) on Jan 23, 2009 at 19:24 UTC
      Thanks! I did search but i'm not sure why I did not come up with this. Thanks again.
Re: List all defined variables
by Fletch (Bishop) on Jan 23, 2009 at 20:20 UTC

    See also the core B::Xref.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: List all defined variables
by chromatic (Archbishop) on Jan 23, 2009 at 20:29 UTC
    It would be nice to be able to reuse the code in other script without needing to modify it everytime a variable is added or deleted.

    In general, you can do this -- you have to work pretty hard not to be able to do this. Are you using lexical variables within your subroutines, passing arguments, and returning values? If not, try that instead.

    (If you're not sure what I meant there, can you show us a small example of code which you have to modify every time you add or delete a variable elsewhere?)