Consider the following code:
### sample1 $_ = 'lrep esu'; $str = reverse lcfirst uc; print $str."\n"; ### sample2 $_ = 'lrep esu'; $str = lcfirst reverse uc; print $str."\n";
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?
In reply to subroutine bewilderment: how to mimic builtins by dimar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |