Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 ( [id://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)

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1051848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found