On Thu, 2003-11-20 at 15:18, Jeff Kowalczyk wrote:
> I'm not yet able to read certain parts of perl code. What is this
> comparison/alternation after the hash lookup on 'otherid' called, and what
> does the code do?
> 
> $myvar->{id} = ($myvar->{otherid}) ? 'stringA' : 'stringB';
> 
> Thanks.

Jeff,

This is the if-then-else operator (for lack of a better term).

The code above could be translated to:

if ($myvar->{otherid}) {
        $myvar->{id} = 'stringA';
} else {
        $myvar->{id} = 'stringB';
}



>From 'perldoc perlop':

Ternary "?:" is the conditional operator, just as in C.  It works much
like an if-then-else.  If the argument before the ? is true, the argu-
ment before the : is returned, otherwise the argument after the : is
returned.  For example:

           printf "I have %d dog%s.\n", $n,
                   ($n == 1) ? '' : "s"


HTH,
Kevin
-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to