Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> For reasons I don't fully understand, barewords preceded by '-' are still allowed, even with "use strict".

I believe the primary motivation for this is so you can pass argument lists to subs in a key => value format without having to quote the key. For example:

  someSub( -opt1 => $opt1val, -opt2 => $opt2val );
[edited for formatting, which I never seem to get right the first time]


You don't have to quote the LHS of the => operator, even if "use strict" is on. (That's the only way that it differs from a regular comma.)

> The "=>" operator (sometimes pronounced "fat comma") is a synonym for the comma except that it causes a word on its left to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores. This includes operands that might otherwise be interpreted as operators, constants, single number v-strings or function calls. If in doubt about this behavior, the left operand can be quoted explicitly.

> Otherwise, the "=>" operator behaves exactly as the comma operator or list argument separator, according to context.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: