In article <>, bobmct <> wrote:
>Fellow mongers;
>
>I've done research in my many perl books as well as numerous perl
>references on the web and still am confused on this rather simple
>situation (embarrassingly so):
>
>I need to compare two variables for presence of content to meet the
>following tests:
>
>VarA = present and VarB = present then false
>VarA = empty and VarB = empty then false
>VarA = present and VarB = empty then true
>VarA = empty and VarB = present then true
I think you need a more precise definition of "present". Do you mean:
a) the variable exists
b) the variable exists and has a value (e.g. non-empty)
c) the variable exists and has a *specific* value (e.g. non-space if a string,
non-zero if a number)
>
>-or-
>
>As I more simply thought of if:
>
>VarA ne VarB then true
That, of course, is an entirely different condition. Two different non-empty
strings are "present", but not equal. The numbers 1 and 2 are present, but,
again, not equal. Moreover, the numbers 1 and 1 are present, and *are* equal.
>
>Each Var could contain
What if the variable doesn't exist?
>
>1) an empty string
Is that "present", or not?
>2) a string value
Presumably, that's "present" -- but what if its value is entirely whitespace
characters (blank, tab, line feed, etc.)?
>3) a numeric value
Presumably, that's "present" too -- but what if the value is zero? Is that
"present"? Do you distinguish between integer zero and floating-point
zero-point-zero?
>4) a space
Is that "present", or not?
>I cannot seem to get a consistent result from the various methods I've
>used.
Perhaps if you posted some of those methods...?
I suspect that the largest part of your trouble is a failure to define clearly
exactly what you mean by "present".
>
>Any recommendations or suggestions greatly appreciated.
Sure -- show us what you've tried, and what happens when you try it.
|