Hello

In the node for loops and 'and' several questions were raised about list context propagation. Much of the weirdness there is due to the semantics of the range (..) operator in scalar context.

My question is slightly more general. perlop says:

Scalar or list context propagates down to the right operand if it is evaluated.
But from the following code, that doesn't seem to be the case. It seems that the left side is always getting scalar context, while right side always gets list. I know that for evaluation the lhs must be "booleanated," but then shouldn't the right side be too? Is it a question of DWIM going haywire?

Thanks.

Code:
use strict; use warnings; sub leftt { wantarray ? print "Left is list\n" : print "Left is scalar\n"; return 1; } sub rightt { wantarray ? print "Right is list\n" : print "Right is scalar\n"; return 1; } sub leftf { wantarray ? print "Left is list\n" : print "Left is scalar\n"; return 0; } sub rightf { wantarray ? print "Right is list\n" : print "Right is scalar\n"; return 0; } print "true or true \n"; my @test = (leftt() or rightt()); print "\@test = @test\n"; print "true or false\n"; @test = (leftt() or rightf()); print "\@test = @test\n"; print "false or true\n"; @test = (leftf() or rightt()); print "\@test = @test\n"; print "false or false\n"; @test = (leftf() or rightf()); print "\@test = @test\n"; __DATA__ Output: true or true Left is scalar @test = 1 true or false Left is scalar @test = 1 false or true Left is scalar Right is list @test = 1 false or false Left is scalar Right is list @test = 0


Who is Kayser Söze?

In reply to Short circut operators in list context by jweed

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.