It would have been useful if you'd posted the original code. Here it is:

use Modern::Perl; say +(split ':')[0] while (<DATA>);

say (and the same goes for print which has fuller documentation) can take a FILEHANDLE as its first argument.

say FILEHANDLE LIST print FILEHANDLE LIST

In short, the '+' indicates that the FILEHANDLE (typically STDOUT) is to be assumed and the arguments following the '+' are the LIST to be output.

Edit: Sorry, that last paragraph was poorly worded. Hopefully, this next one is better. Also see the example code in the Update at the end.

If the FILEHANDLE is omitted, the '+' indicates that the arguments following the '+' (once expanded) are the LIST to be output. If the FILEHANDLE is included, the '+' is not required.

More complete details can be found in print and perlop - Symbolic Unary Operators.

Regarding Modern::Perl, that will effectively do the use feature 'say'; for you; if you comment that out, you will need to do it yourself. I think that's what you were getting at; although, I did get a little lost in the multiple negatives and conditions: "the code works if ... but it doesn't unless ...".

Update: I felt my response might have been misconstrued as being contrary to the previous responses. This is certainly not my intention; in fact, there weren't any responses when I wrote mine. The links to documention that I provided do give more detailed information; however, the following code examples may clarify what I was saying.

$ perl -Mstrict -Mwarnings -E 'my @x = (1,2,3); say (@x)[1]' say (...) interpreted as function at -e line 1. syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.
$ perl -Mstrict -Mwarnings -E 'my @x = (1,2,3); say STDOUT (@x)[1]' 2
$ perl -Mstrict -Mwarnings -E 'my @x = (1,2,3); say +(@x)[1]' 2

-- Ken


In reply to Re: Confused by '+' syntax in code sample. by kcott
in thread Confused by '+' syntax in code sample. 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.