Thanks for clarifying my use of conditional. The question has been answered expertly. I did mean to write compound rather than conditional though. my bad:\

great insights, I have not seen the x!!() operator before.

My question, wrongly put, is really in the second paragraph, why does the if compound statement not compile in list constructors?

using MO=Deparse showed me the if compound statement reduces to a do block so I can take some comfort in my not quite correctly placed assumptions. That is, I was trying to use the if statement as a conditional or rvalue, within a list constructor, when it simply is not one.

The reason for me showing the examples, was to show that context did not make a difference in the syntax compilation, in case that did have a relevance, unfortunately my miss-worded question let me down here.

I was just confused by an if statement not compiling within a list context.

So while thanking you for reminding me about the particular instance of taking a ref to a list, which you will be glad to know, has now sunk in, the if statement within the list does not actually compile. Should it have done in the way the ternary conditional does, then I am sure there are cases where taking refs to the last item in the resultant list do come in useful.

And look, if the vogons recite the virtues of tertiary operators in the poetic redrafts of high order mouse manuals volumes XXXII thru VL then who or what am I to argue?...ahem,oops

my $reftolastscalar = \( "if(1<2){'1'}else{()}" ); my @arr = ( "if(1<2){'1'}else{()}" ); # ref to '2' ? # my $reftolastscalarfromlist = # \('0.99', if(1>2){1}else{(1,2)} ); # does not compile # ref to '42' ? my $reftolastscalarfromlist = \('0.99', 1>2?1:(1,42)); {local $, = "\n"; print $$reftolastscalar,@arr,$$reftolastscalarfromlist,''; # Deparses to: do { print '1','2' }; # :) if(1>2){print '1'}else{print ('1','2')} ; print '',''; } exit 0; ########OP########## if(1<2){'1'}else{()} if(1<2){'1'}else{()} 42 1 2 user@Desktop:~/Desktop$

In reply to Re: conditional statements in list constructors by Don Coyote
in thread conditional statements in list constructors by Don Coyote

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.