in reply to Re: Use of the => operator
in thread Use of the => operator

The leading dash isn't recognized as part of a bareword by =>, it is actually an alternative method for auto-quoting a bareword. Compare:
$ perl -we'use strict; @_ = (-foo, "bar")' $ perl -we'use strict; @_ = (foo, "bar")' Bareword "foo" not allowed while "strict subs" in use at -e line 1.

Replies are listed 'Best First'.
Re^3: Use of the => operator
by etcshadow (Priest) on Aug 09, 2004 at 19:06 UTC
    Absolutely correct! Wow, I'd somehow completely missed that. From perlop:
    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".
    Which leads to this funness:
    [me@host]$ perl -le 'use strict; print -foo; print -"-foo"; print -"+f +oo";' -foo +foo -foo [me@host]$
    Just when you think there's nothing new to learn.
    ------------ :Wq Not an editor command: Wq
Re^3: Use of the => operator
by roju (Friar) on Aug 10, 2004 at 15:23 UTC
    That is really neat - I'd assumed -bareword was just a convention and that => was responsible for the quoting. Is there a reason that - and => aren't mentioned in the "Quotes and Quote-like Operators" section of perlop?
      Becayse they're not "Quotes or Quote-like Operators". The "Comma Operator" gets its own heading and the minus is listed under "Symbolic Unary Operators".