Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found