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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.