Hello shawnhcorey,
This is nice, but it’s probably cleaner to assign the subroutine reference to a lexical variable:
{ my $foo = sub { my ($n) = @_; print "foo($n)\n"; }; $foo->(1); # valid call } $foo->(2); # invalid call
This has the advantage of changing the invalid call from a runtime error into a compiletime error.
From Perl v5.18 on you can also use the experimental Lexical Subroutines feature.
Update: Fixed typo in the code snippet.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^2: Testing private methods a no-no?
by Athanasius
in thread Testing private methods a no-no?
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |