GG1985 has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance,Example 1: ========================= Sample.pl: ---------- #!/usr/bin/perl -w use strict; use Zoo; print $pet, "\n"; Zoo.pm: ------- package Zoo; our $pet = "Cat"; sub import { my $package = shift; my ($callerpkg, $file, $lineno) = caller; ################# # Type-glob below ################# *{"${callerpkg}::pet"} = \${"${package}::pet"}; } 1; Output: ------- >./sample.pl Cat ========================= Example 2: ========================= Sample.pl: ---------- #!/usr/bin/perl -w use strict; use Zoo; print $pet, "\n"; Zoo.pm: ------- package Zoo; our $pet = "Cat"; sub import { my $package = shift; my ($callerpkg, $file, $lineno) = caller; #################### # Symbolic reference below #################### ${"${callerpkg}::pet"} = ${"${package}::pet"}; } 1; Output: ------- >./sample.pl Variable "$pet" is not imported at ./sample.pl line 6. Global symbol "$pet" requires explicit package name at ./sample.pl lin +e 6. Execution of ./sample.pl aborted due to compilation errors. =========================
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of typeglob in package import subroutine
by choroba (Cardinal) on Apr 29, 2014 at 15:03 UTC | |
|
Re: Use of typeglob in package import subroutine
by tobyink (Canon) on Apr 29, 2014 at 15:45 UTC | |
by GG1985 (Initiate) on Apr 29, 2014 at 18:27 UTC | |
by LanX (Saint) on Apr 29, 2014 at 18:33 UTC |