2008/12/5 Raymond Wan <[EMAIL PROTECTED]>:
>
> Hi Dermot,
>
>
> Dermot wrote:
>> Sorry. Someone on the list mentioned to me before, a reference is
>> always true, so the test won't work.
>>
>
> Maybe I have missed something, but it sounds like you want something like
> [NB:  This is not Perl code, but sort of pseudocode]:
>
> if (defined (title1)) {
>  $title = title1;
> }
> elsif (defined (title2)) {
>  $title = title2;
> }
> else {
>  $title = oldtitle;
> }
>
> Is this correct?  If so, the ? operator is not what you want.  What the
> operator does is this.  For "a ? b : c" it does the test on "a" but not on
> "b".  All it does is say, "Is 'a' true?  If so, return 'b'.  Otherwise,
> return 'c'."  You aren't doing any test on b, but it sounds like you want
> to?  (Sorry, you showed your table, but you didn't quite explain what
> title1, title2, and oldtitle means -- so, I am guessing here that you also
> want to test title2?  I am also assuming that you do not want either title1
> or title2, but would prefer title1 -- hence the order of the pseudocode
> above.)


Your right.

I was looking to test title1 and return that if it was defined else,
test title2 and return that if defined, failing that, return oldtitle.
The ? : operator won't do that. It tests title1 and if true returns
title2. That would not be what I was after!

I think we ended up with the same solution. :-) here what I had.


        my $title;
        if (defined($image->title1)) {
                $title = $image->title1;
        }
        elsif (defined($image->title2)) {
                $title = $image->title2;
        }       
        else {
                $title = $image->oldtitle;
        }       

Thanx Raymond,
Dp.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to