Do you know where your variables are? | |
PerlMonks |
goto with anonymous subsby kappa (Chaplain) |
on Sep 12, 2005 at 15:03 UTC ( [id://491276]=perlmeditation: print w/replies, xml ) | Need Help?? |
Hello, fellow monks! Quite often we need to check some conditions right after subroutine entry. Maybe such pattern is actually too elementary and boring to be called a "pattern" in the Gang of Four sense. But let it be so for now. Some conditions are vital to continue, so unless they're met we just scream and return. We usually do something like this:
There're LOTS of ways (both as written practices and as ready CPAN modules) to reduce coding redundancy by creating some pre/post-condition lists and automatically evaluating them on subroutine entry. I've recently found out an interesting way to cut those returns. Maybe that's common knowledge, but I thought it will fit Meditation section.
goto &sub is a well-known way of doing several certain things like calling newly-created subs from AUTOLOAD or jumping to "inherited" parent methods. It can also be used to "switch" to inline anonymous subs (or any coderef) as it turned out -- this is even a documented feature. I've used goto $handler several times with dispatch tables but never goto sub {}. It looks funny (and therefore it's good) :)
--kap
Back to
Meditations
|
|