in reply to Sub signatures, and a vexing parse
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:
I also thought aboutuse Sub::Util qw/set_prototype/; (*Hello, *Hi) = map { set_prototype '\@\@' => $_ } map { my $var = $_; + sub { $_; } } qw/Hello 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 attributes(); sub Hi { "Hi" }; attributes::->import(__PACKAGE__, *{$_}{CODE}, 'prototype(\@\@)') for +*Hi;
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:
|
|---|