in reply to
Can I from within a module access variables from the calling program?
use v5.10;
use strict;
use warnings;
use PadWalker ();
{
package Some::Module;
sub what_is_x {
my $value = $Other::Module::x;
say "\$x is $value";
}
# Just because PadWalker exists, doesn't mean it's a good idea...
sub what_is_y {
my $value = ${ PadWalker::peek_my(1)->{'$y'} };
say "\$y is $value";
}
}
{
package Other::Module;
our $x = 123;
my $y = 456;
Some::Module::what_is_x();
Some::Module::what_is_y();
}
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'