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

Is there an equilvalent way to code the following for 'my' variables?:

#!/perl/bin/perl # # test.pl -- use strict; use warnings; use diagnostics; our $a = 'var a'; our $b = 'var b'; varprint('a','b'); sub varprint { my @list; for (@_) { my $var = $_; my $ref = $main::{$var}; push(@list, "\$$var='$$ref'"); } print join(", ",@list),"\n"; }

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Replies are listed 'Best First'.
Re: 'my' and %main::
by adrianh (Chancellor) on Feb 10, 2003 at 17:32 UTC

    PadWalker will be what you want - although you'll need a good excuse for wanting to do things this evil ;-)

      Looks just the ticket! Much thanks. Re: excuse, didn't Microsoft say that evil was it's own excuse?<g> Any event, this will be self-inflicted only (I promise...)

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."
Re: 'my' and %main::
by MZSanford (Curate) on Feb 10, 2003 at 19:02 UTC
    For completeness, i would like to mention that $a and $b are special because of the affiliation with sort (as reviewed here)
    from the frivolous to the serious
Re: 'my' and %main::
by hsmyers (Canon) on Feb 10, 2003 at 18:17 UTC
    I've just tried PadWalker---which doesn't play well on my NT box (compile dies with bogus error message). So I ammend my search for an equivalent solution under NT...sigh, PadWalker looked really good!

    --hsm

    "Never try to teach a pig to sing...it wastes your time and it annoys the pig."