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(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I from within a module access variables from the calling program?
by HJO (Acolyte) on Oct 25, 2012 at 12:47 UTC | |
by tobyink (Canon) on Oct 25, 2012 at 13:29 UTC | |
by HJO (Acolyte) on Oct 25, 2012 at 13:33 UTC |