I would have upvoted more than once if I could. I'm pretty sure to never do something like that (I still never add to use attributes, and the very few times I used prototypes were on named subroutines) but it was an interesting read nonetheless!

But you could avoid the issue altogether, and in my opinion get a clearer code by setting the prototype or attribute after the declaration:

use Sub::Util qw/set_prototype/; (*Hello, *Hi) = map { set_prototype '\@\@' => $_ } map { my $var = $_; + sub { $_; } } qw/Hello Hi/;
I also thought about
use attributes(); sub Hi { "Hi" }; attributes::->import(__PACKAGE__, *{$_}{CODE}, 'prototype(\@\@)') for +*Hi;
but I can't test it with v5.14 (which doesn't have prototype attributes), and it does not work with the 'lvalue' attribute:
use v5.14; use attributes(); use Data::Dumper; my $Hi; sub Hi:lvalue { $Hi; } my $Hello; sub Hello { $Hello; } BEGIN { attributes::->import(__PACKAGE__, \&Hello, 'lvalue'); } Hi = 'monks'; # It kind of looks like a sigil-less variable actually : +) Hello = 'world'; # There would be a warning here without the BEGIN blo +ck say "Hi: ", Hi; say "Hello: ", Hello; __END__ Hi: monks Hello:


In reply to Re: Sub signatures, and a vexing parse by Eily
in thread Sub signatures, and a vexing parse by davido

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.