I was worried about even posting the reply because I haven't a good story for why it should work apart from Perl DWIMery. As you point out it's not documented as providing that behaviour in any obvious place.
On the other hand it would break a huge amount of code should that behaviour change so I'd guess it ought be safe enough to use.
True laziness is hard work
| [reply] |
| [reply] |
my $obj = This::Class->new( { that => 2, those => 4 } );
He makes the point that a missing 'value' with this strategy would result in compile-time error this way rather than a runtime problem.
Regarding perlmodstyle's mention that the hyphenated parameter tag is based on an antequated need, it does confirm that the behavior of the fat comma is supposed to quote strings with hyphens in them (even at the beginning). So perl and perlmodstyle are both at odds with perlop as to what should qualify for the fat comma's quote-like behavior.
| [reply] [d/l] [select] |
I don't think its related to fat-comma, observe
$ perl -le print-localtime
-Tue Jun 28 00:16:25 2011
| [reply] |
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"?
| [reply] [d/l] [select] |
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 | [reply] [d/l] |