Further to Clarifying the Comma Operator, I am still working towards a revision of the description of the Fat Comma operator (=>) in perlop, and I would appreciate any comments regarding the following.

Currently, perlop says:

If the argument on the left is not a word, it is first interpreted as an expression, and then the string value of that is used.

So I tested this and I am suspicious that it is not true. Consider the following:

use strict; use warnings; use Devel::Peek; sub mysub { Dump(\@_); } my $x = 10; Dump(\$x); mysub( $x => "a string" );

This produces:

SV = RV(0x9fc41fc) at 0x9fc41f0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x9fd4418 SV = IV(0x9fd4414) at 0x9fd4418 REFCNT = 2 FLAGS = (PADMY,IOK,pIOK) IV = 10 SV = RV(0x9fc41fc) at 0x9fc41f0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x9fd43f8 SV = PVAV(0x9fc528c) at 0x9fd43f8 REFCNT = 3 FLAGS = () ARRAY = 0x9fd81f8 FILL = 1 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x9fd4414) at 0x9fd4418 REFCNT = 2 FLAGS = (PADMY,IOK,pIOK) IV = 10 Elt No. 1 SV = PV(0x9fc20e8) at 0x9fe0a08 REFCNT = 2 FLAGS = (POK,READONLY,pPOK) PV = 0x9fd56f8 "a string"\0 CUR = 8 LEN = 12

The first element of @_ in the subroutine is an alias to $x. It is not the result of taking the string value after evaluating the expression $x. Therefore, it seems to me that the description of the => operator is incorrect.

If my test results are consistent with the description, a smack on the head would be appreciated, followed by anything that might help correct my misunderstanding. If not, suggestions of what the correct description is would be even more appreciated.

To begin with, I suspect that if the left operand of => isn't a word with the form of a simple identifier then the left operand of => is handled the same as if => was a comma. But the "list in scalar context" discussions make me mindful that I don't know all I might about the comma operator and might easily jump to wrong conclusions about what is happening.

update: Sorry, I didn't realize I had posted some earlier version of this, went on merrily editing and then hastily clicked update without checking to see what was originally posted.


In reply to Further clarification of the Fat Comma 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.