It's interesting that the "warn" part won't work without the parens, but the "next" works in any case -- consider:
%h=qw/a 1 b 0 c 2/; while (($k,$v)=each %h) { $x=$v or warn("got a false value for key $k"),next; # $x=$v or warn "got a false value for key $k", next; print "got a true value for key $k: $v\n"; }
When the parens are there, you get the warning. When you comment the line with parens and uncomment the other, you still get only two lines printed to STDOUT, but nothing printed to STDERR.

Apparently, when the parens are removed, the comma-separated things after "warn" are grouped and treated as args passed to warn -- and the second arg happens to be an expression that must be evaluated in order to pass the resulting value as an arg. But evaluation of "next" as the second arg has the effect of jumping directly to the next loop iteration -- so warn never gets called.

By putting parens around the single arg to "warn", you make sure that this expression is fully evaluated, and then the "next" expression is also evaluated, causing the jump to the next iteration. The comma binds tighter than "or", so the expressions separated by commas are evaluated as if they were a block relative to "or".


In reply to Re: using 'or' followed by ',' by graff
in thread using 'or' followed by ',' by mathew_

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.