in reply to Abuse of "or next" in expressions and "next" that returns value

next is not a function, so does not return a value. Nor does it need to return a value. It is either executed or not. If executed, the expression containing it never gets a chance to use anything next didn't provide. If not executed, then the other subexpression had a non-false value which became the value of the containing expression.

In this case, ${next unless $_;}, if $_ is non-false, the evaluator skips everything to the left of unless, so next isn't executed.

I do agree that ${next unless $_;} is surprising syntax. Still, it is valid and semantically equivalent to $_ or next

Replies are listed 'Best First'.
Re^2: Abuse of "or next" in expressions and "next" that returns value
by vr (Curate) on Jul 19, 2018 at 07:23 UTC

    Thank you everyone for answers, now it became more clear. As I understand, every statement in Perl "returns" a value -- rather, it can be evaluated if program flow requires it. The bare "next;" is a statement. What it evaluates to is never necessary to know. The "foo unless bar;" is a statement, too. If "bar" is false, it obviously evaluates to "foo". But if "bar" is true, this whole statement, unexpectedly to me as of yesterday, evaluates to "bar":

    >perl -wE "$x=33; say do{42 unless $x}" 33

    The (wrong) intuition was that result would be something like "undef". But, if I get RonW's explanation right, the "evaluator" is more straightforward and "primitive" -- it doesn't try to "understand" statement as a whole, but whatever subexpression was evaluated last is taken as result for a whole.