Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^5: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway. (mini-if ternary)

by Anonymous Monk
on Sep 01, 2013 at 19:13 UTC ( #1051848=note: print w/ replies, xml ) Need Help??


in reply to Re^4: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.
in thread CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway.

Sure, but you can't invent your own syntax, you have to use perl's.

In perl, commas are not comma-colons I mean colon-commas semicolons . You can't just plop an if(){}statement into the middle of an expression (What is the difference between a Statement and an Expression?). if is a control structure (a block) , it controls the flow of the program (branch/decision).

But, you can do what you were thinking of with a do-block, or switch to the Conditional Operator (mini-if, ternary, trinary, terrychilds)


Comment on Re^5: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway. (mini-if ternary)
Re^6: CGI::Ajax No head/html tags, nowhere to insert. Returning javascript anyway. (mini-if ternary)
by Anonymous Monk on Sep 01, 2013 at 19:17 UTC
    do { if( ... ) { ...; $return->last_statement; } }

    extra parenthesis -MO=Deparse,-p style

    ( ( if_condition_true() ) ? ( then_return_this() ) : ( else_return_this() ) )

    :D

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (16)
As of 2014-04-16 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls