|Perl: the Markov chain saw|
subroutine bewilderment: how to mimic builtinsby dimar (Curate)
|on Feb 07, 2006 at 22:57 UTC||Need Help??|
dimar has asked for the
wisdom of the Perl Monks concerning the following question:
Consider the following code:
Each sample produces a different result, but neither one generates an error. This is true regardless of the order in which I specify the built-in functions. Moreover, I do not have to specify parenthesis or an input argument. The functions implicitly work on $_ by default.
Question: suppose I have a custom subroutine "spaces_to_und" that converts spaces to underscores. How do I declare the subroutine so that it works *just like* the built-in lcfirst, reverse and uc functions?
The goal is to operate on $_, just like built-ins, as well as obviate the need to use parens, as well as the ability to call the functions in any relative order in the source code, without generating an error.
To pull this off, prototyping is surely required, but no proof-of-concept has yet been found. Is this even possible?