in reply to Using join and ternary operator together

Thanks all for the replies. My syntax and logic both were incorrect. The working code is this: my $stmt = join " ", "select * from dbo.server" , defined($orderby) ? "order by $orderby;" : ";" ;

Replies are listed 'Best First'.
Re^2: Using join and ternary operator together
by boftx (Deacon) on Sep 11, 2013 at 03:04 UTC

    Just a pet peeve for the most part, but I prefer using parens even when they are not strictly needed just to improve clarity of intent. Seems to help me, anyway.

    my $stmt = join(" ", "select * from dbo.server" , (defined($orderby) ? + "order by $orderby;" : ";"));

    On a side note, I presume you have a space in front of the word "order" in your true clause. I.e. " order by $orderby;" or else you would wind up with SQL that read something like this: select * from dbo.serverorder by .... That would clearly be wrong.

      ... a space in front of the word "order" in your true clause.

      That space would be supplied by the  " " join string of the join function.

        Good catch, I should know better than to try catching stuff like when I'm that tired. I thought that was too obvious. :)