From: Dermot <[EMAIL PROTECTED]> > 2008/12/5 Raymond Wan <[EMAIL PROTECTED]>: > > 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!
Do you insist on the "defined"? I mean what if title1 is an empty string instead? Or zero? If you do not mind we treat those two as an undef them $title = $title1 || $title2 || $old_title; is enough. In Perl 5.10 there is a new operator // that tests the defined()ness so there you could write $title = $title1 // $title2 // $old_title; and it would mean exactly what you said you need. It will set $title to $title1 if defined, otherwise to $title2 if defined and otherwise to $old_title. HTH, Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/