in reply to Re: Parameter list wierdness
in thread Parameter list wierdness

aah, that works and it's much nicer. Still think I'm missing something about how the ternary operator works though!

Thanks, Cxx

Replies are listed 'Best First'.
Re^3: Parameter list wierdness
by Grygonos (Chaplain) on Jul 01, 2004 at 16:45 UTC

    my $value = (if condition? then this: else this);
    That's about the quickest explanation. Ternary should never be used in void context. See my node Ternary in void context where I cleared up my ternary confusion as well. The ternary operator always returns the value present in its truth branch (for lack of a better term), that's why you shouldn't substitute it for if then constructs.

    an if then construct that warrants a ternary is similar to the following

    if($some_var eq 'X') { $this_var = 'Run using X format'; } else { $this_var = 'Run using standard format'; }
    This would equate to the ternary
    $this_var = ($some_var eq 'X'? 'Run using X format':'Run using standar +d format');