Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Is it possible to create a sub exclusive to a sub?by Aristotle (Chancellor) |
on Sep 19, 2004 at 07:38 UTC ( [id://392130]=note: print w/replies, xml ) | Need Help?? |
Update: ihb pointed this out before I did. All of the other solutions so far create the anonymous sub inside the calling sub, so they recreate it on every call. A better way that avoids that wasted effort would be
The BEGIN avoids a trap for the unwary: you might otherwise call foo() before the assignment to $bar has run, blowing up the script. If this code is in a module, there is an implicit BEGIN around all of the code, so this might not be necessary (your call), but it's a good defensive habit nonetheless. Makeshifts last the longest.
In Section
Seekers of Perl Wisdom
|
|