On Sun, Dec 08, 2002 at 03:25:17PM +1100, Damian Conway wrote:
> Kate L Pugh wrote:
> 
> >  [hummous: kake]$ perl -MData::Dumper -we 'use strict; my $foo = [ -foo 
> >  ]; print Dumper $foo'
> >  $VAR1 = [
> >            '-foo'
> >          ];
> >  [hummous: kake]$
> >
> >Where's this documented?
> 
> The perlop manpage:
>       
>     Unary "-" performs arithmetic negation if the operand is numeric. If the
>     operand is an identifier, a string consisting of a minus sign
>     concatenated with the identifier is returned. Otherwise, if the string
>     starts with a plus or minus, a string starting with the opposite sign is
>     returned. One effect of these rules is that `-bareword' is equivalent to
>     `"-bareword"'.
> 
> It's commonly used to pass named arguments:
> 
>       set_lang( -name=>'Perl', -paradigm=>'hybrid', -motto=>'TMTOWTDI' );

But barewords are not allowed under strict. So why is -bareword being allowed?
I knew about:

$ perl5.8.0 -wle 'print -foo'
-foo
$ perl5.8.0 -wle 'print -(-foo)'
+foo

but I never realised that these worked:

$ perl5.8.0 -wle 'use strict; print -foo'
-foo
$ perl5.8.0 -wle 'use strict; print -(-foo)'
+foo

Not much strict there, it seems :-(

[And I doubt that it can be changed without getting arrested by the backwards
compatibility police. use strict 'stricter'. Except that it looks like
attempts to turn on more stricture don't work as hoped for:

$ perl5.8.0 -wle 'use strict qw(bondage discipline); print STDOUT foo'
Unquoted string "foo" may clash with future reserved word at -e line 1.
foo

compare with:
$ perl5.8.0 -wle 'use strict; print STDOUT foo'
Bareword "foo" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
]

Nicholas Clark
-- 
INTERCAL better than perl?      http://www.perl.org/advocacy/spoofathon/

Reply via email to