c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"sub func { print qq{hey @_}; }
my $symref = 'func';
our $symref = 'func';
;;
my $mainobj = bless [];
dd $mainobj;
;;
main->$symref('ho');
$mainobj->$symref('there');
;;
&$main::symref('nonny-nonny');
"
bless([], "main")
hey main ho
hey main=ARRAY(0x157618c) there
Can't use string ("func") as a subroutine ref while "strict refs" in use at -e line 1.
c:\@Work\Perl\monks>perl -w -MData::Dump -le
"sub func { print qq{hey @_}; }
my $symref = 'func';
our $symref = 'func';
;;
my $mainobj = bless [];
dd $mainobj;
;;
main->$symref('ho');
$mainobj->$symref('there');
;;
&$main::symref('nonny-nonny');
"
bless([], "main")
hey main ho
hey main=ARRAY(0x185614c) there
hey nonny-nonny
####
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"sub func { print qq{hey @_}; }
sub bonk { print qq{zot @_}; }
;;
my $symref = 'func';
;;
use vars qw($symref);
$main::symref = 'bonk';
;;
my $mainobj = bless [];
dd $mainobj;
;;
main -> $symref('ho');
'main' -> $symref('hi');
my $mainstring = 'main';
$mainstring -> $symref('he');
$mainobj -> $symref('there');
;;
no strict 'refs';
&$main::symref('nonny-nonny');
"
bless([], "main")
hey main ho
hey main hi
hey main he
hey main=ARRAY(0x37716c) there
zot nonny-nonny
####
my $str = 'aaa';
for my $alias (main::, 'main', $mainstring, $mainobj) {
$alias->$symref($str++);
}