On Thu, 7 Feb 2002, Balint, Jess wrote:

> Hello all. I have the following construct:
>
>         $freqidx{$key}[$_] += $fields[$vars[$_-1]] for( 0..$#vars );
>
> It is inside some type of loop. What I need to do is use the conditional
> operator if possible to do something like this:
>
> if( $fields[$vars[$_-1]] ne "" ) {
>       $freqidx{$key}[$_] += $fields[$vars[$_-1]];
> } else {
>       $freqidx{$key}[$_] += 0;
> }
>
> For a final resolution along the lines of:
>
> ( $fields[$vars[$_-1]] ne "" ? $freqidx{$key}[$_] += $fields[$vars[$_-1]]; :
> $freqidx{$key}[$_] += 0; ) for( 0..$#vars );

Why even do the += 0, since that just makes the value the same? In fact,
all you really need to do is see if $fields[$vars[$_-1]] is a defined
value:


foreach(0..$#vars) {
  $freqidx{$key}[$_] += $fields[$vars[$_-1]] if defined $fields[$vars[$_-1]];
}

-- Brett

                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
Nihilism should commence with oneself.


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

Reply via email to