note
choroba
You can do that with the symbol table, but using [doc://defined] and [doc://exists] is cleaner.
<c>
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
{ package My;
sub one { print "123"; }
sub two;
}
say ${My::}{one}; # *My::one
say ${My::}{two}; # -1
say ${My::}{three}; #
say defined *My::one{CODE}; # 1
say defined *My::two{CODE}; # 1
say defined *My::three{CODE}; #
say exists &My::one; # 1
say exists &My::two; # 1
say exists &My::three; #
say defined &My::one; # 1
say defined &My::two; #
say defined &My::three; #
</c><P>
<B>Update:</B> added the first paragraph of says.<P>
<B>Update 2:</B> Interestingly, a forward declared sub with prototypes returns the prototypes with the first syntax:
<c>
sub four (&@);
# ...
say ${My::}{four}; # &@
</c><P>
<B>Update 3:</B> ... unless you add an attribute, too, which makes it output the glob name.
<c>
sub five (&@) :method;
say ${My::}{five}; # *My::five
</c><P>
<B>Update 4:</B> The -1 is printed only if you remove all other mentions of My::three, otherwise <c>*My::three</c> is printed.<P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-832495">
<c>map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]</c>
</div></div>
<!-- Wiki2Monks {"version":1.142} -->
1230721
1230721