with a note of : (The + is in the above line is a no-op, used to tell grep that the parentheses are not enclosing its arguments.) what does that note actually mean?

If grep is immediately followed by an opening parenthesis, that parenthesis would be interpreted as starting the argument list of grep, so for example grep( /foo/, @array ) or grep( {$_>123} @array ). However, in this case, the expression being used to search the list is "()=@$_". One could write this in the grep BLOCK LIST form of grep as grep {()=@$_} @arrays, however, in this case the author has chosen the grep EXPR, LIST form of grep. But if one wrote grep ()=@$_, @arrays, then Perl would think that you were calling grep with no arguments ("grep()"), followed by "=@$_, @arrays", which is invalid syntax. Therefore, to tell Perl that the parentheses are actually not introducing the arguments of grep, one has to disambiguate and add the + operator. Because in this case it has no effect except informing the Perl parser, it is in that sense a no-op. Another way to disambiguate the situation would have been an extra pair of parentheses, as in grep( ()=@$_, @arrays ).

This is one of the reasons that I perfer the BLOCK LIST forms of grep and map, and the same issue with parentheses commonly comes up in the arguments to print.

Typo fix in the last sentence.

Update: In this case, the use of the "Saturn" "secret" operator doesn't even really make sense, since all that is being done is that empty array references are being filtered out. This could be written as grep {@$_} @arrays (or grep @$_, @arrays), or if one wanted to be explicit that one is filtering on the number of elements the arrays contain, e.g. grep {0+@$_} @arrays.


In reply to Re: Perlsecret - plus no-ops (updated) by haukex
in thread Perlsecret - plus no-ops by Anonymous Monk

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.