in reply to subroutine return ternary output

It looks like a typo to me: you have $1 in the second example, and this is probably not defined. Also your brackets may be misplaced.

This should work in the same way as your original:

return (0 eq system "$KSH_SCRIPT") ? 1 : 0;

Now, whether you should be comparing the return code of system with "0" (eq is a string comparison) is a different matter...


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re^2: subroutine return ternary output
by earl_the_perl (Novice) on Sep 07, 2004 at 14:32 UTC
    Yes muntfish I did create a typo when submitting to perlmonks.
    return (0 eq system "$KSH_SCRIPT"?$1:2);
    should be...
    return (0 eq system "$KSH_SCRIPT"?1:0);
    Using your advice and changing my paran's made it work:
    return (0 eq system "$KSH_SCRIPT")?1:0;
    All is well now. Interestingly enough both "eq" and "==" work as expected on testing the return code. I assume it comes back as an integer and perl converts for us? Thanks for the help!!