http://qs1969.pair.com?node_id=1080029


in reply to conditional statements in list constructors

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$