Excellent suggestion. I wouldn't use "identifier", as that suggests other connotations to me and doesn't fit how I'm used to seeing Perl documented.

I would change "any word" to "a word". I find "any word" potentially misleading, as it could be interpretted as applying to words that are part of some larger expression to the left of the fat comma.

My first choice was to change "any word" to "a bareword", but the definition given for "bareword" in perldata is actually too narrow for this case. I define "bareword" as a "bare word", an unadorned word that Perl first tries to interpret as an operator or function call and then resorts to quoting if strict.pm doesn't prevent it. perldata defines "bareword" as "a bare word that doesn't mean something else", which I find unfortunate but acceptable.

Note that elsewhere in perldata it says:

The => operator is mostly just a more visually distinctive synonym for a comma, but it also arranges for its left-hand operand to be interpreted as a string -- if it's a bareword that would be a legal simple identifier (=> doesn't quote compound identifiers, that contain double colons).

which isn't using the "bareword" definition found in that same document (otherwise it would mean that x, for example, won't be turned into a string by => since x isn't a "bareword" according to the perldata documentation).

Update: Actually, even though x is an operator, it can also be a "bareword" that just gets quoted if strict.pm isn't in effect. Perhaps "if", "s", or "q" would've been better examples. I'm not absolutely certain that an unadorned ("bare") instance of "if", "s", or "q" can never turn into a bareword that gets stringified, but I can't think of any counterexamples. For example, try replacing "x" with other things in perl -MO=Deparse -e "0+x" vs in perl -MO=Deparse -e "print x=>0".

perldata also says:

In fact, an identifier within such curlies is forced to be a string, as is any simple identifier within a hash subscript. Neither need quoting.

just to note how the same situation is described for another case.

Finally, my example of x reminds me that the clarification should be expanded to "considered an operator, constant, or function call".

- tye        


In reply to Re: Clarifying the Comma Operator (bareword) by tye
in thread 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.