in reply to Memory efficiency, anonymous vs named's vs local subroutines
Just to demonstrate the effect of dynamic scoping that AnomalousMonk already described:
sub foo { local *bar = sub { print "other bar\n"; }; print "foo calling quz\n"; quz(); } sub bar { print "bar\n"; } sub quz { print "quz calling bar\n"; bar(); } foo(); quz(); __END__ Subroutine main::bar redefined at - line 4. foo calling quz quz calling bar other bar quz calling bar bar
Despite the warning about the subroutine being redefined, this can cause some spooky action-at-a-distance effects: How do you know which bar() you'll be calling (as demonstrated by sub quz)?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Memory efficiency, anonymous vs named's vs local subroutines
by thanos1983 (Parson) on Jul 18, 2015 at 19:42 UTC |