in reply to Re^3: How should named paramater keys be named?
in thread How should named paramater keys be named?

Oh!!! Thank you! Well, now you led me to remember an answer, while opening a question.

When you mentioned that it's not related to the fat-comma, you reminded me that hyphen itself is special, and that led me to this in perlop Symbolic Unary Operators:

Unary "-" performs arithmetic negation if the operand is numeric, including any string that looks like a number. 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 the string "-bareword". If, however, the string begins with a non-alphabetic character (excluding "+" or "-"), Perl will attempt to convert the string to a numeric and the arithmetic negation is performed. If the string cannot be cleanly converted to a numeric, Perl will give the warning Argument "the string" isn't numeric in negation (-) at ....

So that answers that: It's not fat-comma that's quoting a -key=>'value' pair, it's the hyphen.

And that leads to the question. Why is -localhost not treated like -bareword, or in other words, "-localhost"?


Dave

Replies are listed 'Best First'.
Re^5: How should named paramater keys be named?
by Anonymous Monk on Jun 28, 2011 at 08:23 UTC
    It is treated like a bareword
    $ perl -le " print scalar nekkid " nekkid $ perl -le " sub nekkid { localtime } print scalar nekkid " Tue Jun 28 01:13:12 2011 $ perl -le " print-nekkid " -nekkid $ perl -le " sub nekkid { localtime } print-nekkid " Ambiguous use of -nekkid resolved as -&nekkid() at -e line 1. -Tue Jun 28 01:05:22 2011
    It seems, in addition to perltrap, there is a need for a FMTYEWTK barewords, because barewords are trouble, see (tye)Re: Filehandles vs. Packages: And the winner is... and its parents