Dr.Ruud wrote:
>
> "John W. Krahn" schreef:
>>
>> Dr.Ruud wrote:
>>>
>>> Yes, "passing the bareword test" is a better phrase than only
>>> mentioning "word" characters.
>>>
>>> There are border cases though:
>>>
>>> perl -Mstrict -MData::Dumper -wle'
>>> $_ = { AB => 1, +AB => 2, -AB => 3 };
>>> print Dumper $_
>>> '
>>> $VAR1 = {
>>> '-AB' => 3,
>>> 'AB' => 2
>>> };
>>
>> It depends on what you mean by "border case"?
>
> Well, I expected both +AB and -AB would trigger a "bareword" error.
> But also like this:
>
> $ perl -Mstrict -wle 'my $x = -XY; print $x'
>
> there is no error message.
>
>
> With a "+" it is different though:
>
> $ perl -Mstrict -wle 'my $x = +XY; print $x'
> Bareword "XY" not allowed while "strict subs" in use at -e line 1.
> Execution of -e aborted due to compilation errors.
>
>
>> Unary plus and unary minus appear to be behaving correctly. :-)
>
> Right. :)
perldoc perlop
[ snip ]
Symbolic Unary Operators
[ snip ]
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".
^^^^^^^^^^^^^^
[ snip ]
Unary "+" has no effect whatsoever, even on strings. It is useful
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
syntactically for separating a function name from a parenthesized
expression that would otherwise be interpreted as the complete list of
function arguments. (See examples above under "Terms and List
Operators (Leftward)".)
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/