in reply to Ampersand prefix for package constants ?
Calling subroutines with an ampersand but without parentheses is a special invocations that preserves @_ and should only be used in special advanced situations. This is not one of those.
You'd be better off writing POSIX::O_RDWR() or (if you used strict) POSIX::O_RDWR. Some information related to such choices is summarized in (tye)Re: A question of style.
Update: For those players at home confused by this answer (thinking I got my advice backward as far as strict.pm is concerned, one of whom was kind enough to /tell me about it)... The point of strict.pm is pretty much to catch simple mistakes, including typos.
Let's take two simple mistakes as examples: 1) you mispelt "O_RDWR" or 2) forgot to "use POSIX". Now consider these correct usages:
which gives us results similar to the following:perl -le " use POSIX; print 'x',POSIX::O_RDWR();" perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWR();" perl -le " use POSIX; print 'x',POSIX::O_RDWR;" perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWR;"
Now consider these mistakes:> perl -le " use POSIX; print 'x',POSIX::O_RDWR();" x2 > perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWR();" x2 > perl -le " use POSIX; print 'x',POSIX::O_RDWR;" x2 > perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWR;" x2
which are all caught for us as follows:perl -le " print 'x',POSIX::O_RDWR();" perl -le " use POSIX; print 'x',POSIX::O_RDWT();" perl -le "use strict; print 'x',POSIX::O_RDWR();" perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWT();" perl -le "use strict; print 'x',POSIX::O_RDWR;" perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWT;"
and finally consider these mistakes:> perl -le " print 'x',POSIX::O_RDWR();" Undefined subroutine &POSIX::O_RDWR called at -e line 1. > perl -le " use POSIX; print 'x',POSIX::O_RDWT();" O_RDWT is not a valid POSIX macro at -e line 1 > perl -le "use strict; print 'x',POSIX::O_RDWR();" Undefined subroutine &POSIX::O_RDWR called at -e line 1. > perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWT();" O_RDWT is not a valid POSIX macro at -e line 1 > perl -le "use strict; print 'x',POSIX::O_RDWR;" Bareword "POSIX::O_RDWR" not allowed while "strict subs" in use at -e +line 1. Execution of -e aborted due to compilation errors. > perl -le "use strict; use POSIX; print 'x',POSIX::O_RDWT;" Bareword "POSIX::O_RDWT" not allowed while "strict subs" in use at -e +line 1. Execution of -e aborted due to compilation errors.
which are not caught for us:perl -le " print 'x',POSIX::O_RDWR;" perl -le " use POSIX; print 'x',POSIX::O_RDWT;"
and you see why I say you should only write POSIX::O_RDWR if you used strict (because if you try to write POSIX::O_RDWR without using strict.pm, you aren't protected from a simple mistake going unreported). - tye> perl -le " print 'x',POSIX::O_RDWR;" xPOSIX::O_RDWR > perl -le " use POSIX; print 'x',POSIX::O_RDWT;" xPOSIX::O_RDWT
|
|---|