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


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)

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