http://qs1969.pair.com?node_id=1174968

perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:

I had things working and then decided to break this program into 3 parts. The 1st part had a jump-table, of sorts, where a bunch of anon subs were called depending on what keyword matched. Some were named because they were reused by other routines.

When I turned the 1st part into its own package, the call to the subs via the "local" name, stopped working.

Created 2 call types in a test. asub can only be called if I don't declare it w/local -- Can't I declare it?

bsub is local to a procedure, for it, the local call has no effect (bsub is callable from within "do_internal_sub" either way. Oddly, even though the "local *bsub" would seem to include "stuff" in its lexical scope, instead of the eval telling me that bsub was not set, it says it can't find bsub.

So why does the "local *bsub" have no effect and why does the inclusion of "local *asub" prevent it from being callable in "stuff", below?

#!/usr/bin/perl { package Do::Stuff; use warnings; use strict; use P; sub setup{my $p=shift; my $c=ref $p||$p; bless $p={}, $c unless ref $p; $p; } #local *asub; *asub = sub { P "asub called with %d param%s%s.", 0+@_, -1+@_?"s":" +", @_ ? P(" (%s)", \@_) : ""; 1}; local *bsub; sub do_internal_sub() { my $p=shift; *bsub = sub{ P "Called with %d param%s%s.", 0+@_, @_-1?"s":"", @_ ? P(" (%s)", \@_) : ""}; P "calling bsub: %s", &bsub("one",2,"III"); } sub stuff() { my $p=shift; P "In stuff"; eval {&asub("stuff")}; if ($@) { P "asub call gave: $@"; } eval {&bsub("more", "stuff")}; if ($@) { P "bsub call gave: $@"; } } 1} package main; use warnings; use strict; use P; my $p=Do::Stuff->setup; P "calling stuff..."; $p->stuff; P "calling internal_sub: %s", $p->do_internal_sub;

P.s - Obviously, I can hack together something that will work, but there sure seem to a few inconsistencies which always tend to bug me... Thanks!