in reply to why avoid & on function call
In Perl 4 the &sigil was mandatory, Perl 5 changed this.
IIRC it has now a bunch of side effects like°
- disabling prototype check when passing arguments
- reusing the caller's @_ when not passing arguments
This can be very useful in edge cases <1‰, but will more likely cause trouble in normal use.
The only time you can't avoid &sigils in standard Perl5 is when referencing a named function ˛
$code_ref = \&sub_name
More in perlsub ...
HTH :)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
Updates
°) other use case are:
- calling a post-declared sub without parens().
E.G. like when wanting to use AUTOLOAD while avoiding parenthesis for syntactic sugar.
- calling a sub named after a built-in
E.g. CGI.pm used to have a sub &tr for HTML's "table row" tag which collided with Perl's tr (IIRC)
- ˛) some built-ins require & with named subs as arguments, like goto, map , grep , sort
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: why avoid & on function call (updated x 3)
by Anonymous Monk on Dec 28, 2020 at 19:38 UTC | |
by LanX (Saint) on Dec 28, 2020 at 20:14 UTC |
In Section
Seekers of Perl Wisdom