Single-character non-alpha (plus _) subroutines are global
$ perl -le '** = sub {warn "Hi"}; package Foo; &*'
Hi at -e line 1.
$ perl -le '*a = sub {warn "Hi"}; package Foo; &a'
Undefined subroutine &Foo::a called at -e line 1.
and:
$ perl -le '*_ = sub {warn "Hi"}; package Foo; &_'
Hi at -e line 1.
$ perl -le '*__ = sub {warn "Hi"}; package Foo; &__'
Undefined subroutine &Foo::__ called at -e line 1
This came up when I was looking at _() in Perl as a potential Gettext
wrapper (I know about the _ filehandle).
_ I think I can understand (presumably the _ glob is global). But why
does this apply generally to all /^[\W_]$/ subs? Is it explicitly
documented somewhere? Perhaps it's something we'd want to deprecate?
1. http://search.cpan.org/~guido/libintl-perl-1.19/lib/Locale/libintlFAQ.pod#Why_does_Locale::TextDomain_use_a_double_underscore?_I_am_used_to_a_single_underscore_from_C_or_other_languages.
Thread Next