Further to Illegal octal digit error, I am inclined to submit a document patch for Comma Operator to clarify handling of bare words to its left. Currently it says:

The "=>" operator is a synonym for the comma, but forces any word (consisting entirely of word characters) to its left to be interpreted as a string (as of 5.001). This includes words that might otherwise be considered a constant or function call.

I am inclined to suggest:

The "=>" operator is a synonym for the comma, but forces any word (beginning with an underscore or alphabetic character and consisting entirely of word characters) to its left to be interpreted as a string (as of 5.001). This includes words that might otherwise be considered a constant or function call but does not include numeric literals.

JavaFan has suggested identifier which maybe should replace word. It seems better to me but I worry that identifier might have limitations that would not be appropriate. Maybe the phrase "but forces any bare word that could be a valid identifier" would be correct, but it seems rather wordy (no pun intended).

ikegami said perldata defines a bareword as "a word that has no other interpretation in the grammar" and The thing is, a bareword "will be treated as if it were a quoted string." That means => does nothing except prevent the default behaviour from being "outlawed" using use strict 'subs';.. While I find these statements very suggestive I am not sure I know what they mean. They may be very correct but I'm not sure they lead one easily to a full understanding. I will have to think a bit. Until then, I don't know whether or how to try to fit this information in.

Any comments or suggestions would be welcome, including please leave it alone if there are people who think it is clear and correct as it is.

update: My current draft revision begins as follows. This does not include examples, which I will deal with after settling on the preliminary description.

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

Otherwise, the "=>" operator behaves exactly as the comma operator.

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

See also Further clarification of the Fat Comma.


In reply to Clarifying the Comma Operator by ig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.