Instead of non-working '+' or offending '()', you could use '&'
That's evil, I love you ;-)
Note that this has an interesting side effect that you'll never be able to observe:
use constant foo => 'bar'; sub crack { print &foo, $/; } crack(1, 2, 3);
constant creates a sub foo () { 'bar' }, that is a constant sub with empty prototype.
Using the & in front bypasses the prototype check, and it passes all arguments of sub crack to sub foo.
Now since foo is constant sub, you have no way of observing the difference - except for speed:
use Benchmark qw(cmpthese); cmpthese(-1, { 'ampersand' => 'use constant foo => 2; my $x = 0; for (1..10000) { + $x += &foo } ', 'no_amp' => 'use constant foo => 2; my $x = 0; for (1..10000) { + $x += foo } ', }); __END__ Rate ampersand no_amp ampersand 570/s -- -39% no_amp 939/s 65% --
You can see that number of passed arguments makes a difference with this small benchmark:
cmpthese(-1, { 'ampersand' => ' use constant foo => 2; sub a { my $x = 0; for (1..10000) { $x += &foo } } a(%ENV, %ENV, %ENV) ', 'no_amp' => ' use constant foo => 2; sub a { my $x = 0; for (1..10000) { $x += foo } } a(%ENV, %ENV, %ENV) ', }); __END__ Rate ampersand no_amp ampersand 330/s -- -61% no_amp 849/s 157% --
Passing a relatively large array to the sub increase the run time difference.
In reply to Re^2: On quoting the lhs of '=>'
by moritz
in thread On quoting the lhs of '=>'
by rovf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |