is basically syntactic sugar for:use constant FOO => 42;
sub FOO { 42 }
Normally, you wouldn't need to use the & sigil, but many of the POSIX constants are basically AUTOLOADed subroutines. So I bet you have something like:
at the start of your program. Because the subroutines have not been encountered at compile time, the compiler needs a hint that it is a subroutine (otherwise it will assume it is a "bareword"). Observe:use POSIX ();
$ perl -mPOSIX -e '$a = POSIX::O_RDWR; print "$a\n"' POSIX::O_RDWR $ perl -mPOSIX -e '$a = &POSIX::O_RDWR; print "$a\n"' 2
An alternate way is to export the constant your own namespace so that you can refer to it directly without the POSIX:: prefix:
or, as a one liner:use POSIX qw(O_RDWR);
$ perl -mPOSIX=O_RDWR -e '$a = O_RDWR; print "$a\n"' 2
Hope this helps.
Liz
In reply to Re: Ampersand prefix for package constants ?
by liz
in thread Ampersand prefix for package constants ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |