Dearest Monks,
I ran into a problem where I needed a function similar to Oracle's NVL function. For those of you who aren't Oracle people, the function substitutes a value for a returned NULL. A co-worker pointed me to the ( ? : ) operators. However, I've found a small problem with it. Well, let me show you.
my $junk;
print 1+$junk;
Returns an unitialized value warning, as expected.
print 1+($junk ? $junk : 0);
Returns 1, no warning.
$junk = 11;
print 1+($junk ? $junk : 0);
Returns 12, seems to do what I want, but...
$junk=0;
print 1+($junk ? $junk : 15);
returns 16, even though the value was defined as 0.
So, clearly this only worked because I didn't need a different number to be returned. I can see this coming to bite me later. So, I guess my question is, does anyone know of a function that will do what I'm looking for? Is this an obvious misuse of
? : operators?
I'm sorry this was so wordy for so small a question..
Marty