Vance M. Allen <mailto:[EMAIL PROTECTED]> wrote:

: I have several places in my code where I need to check if two
: string variables are empty, if one is empty and the other is
: not, and if they're both populated.
:
: Is there any simpler way to write the code than this?

    No. At least there is no perl built-in way to rewrite it. You
could use a subroutine, but you haven't supplied enough details to
get detailed help. For example, if the response is always he same
then this may work.

compare( $var1, var2 );

# or

my @result = compare( $var1, var2 );

sub compare {
    my @fields = @_;

    if ( $fields[0] eq '' and $fields[1] eq '' ) {
        # Neither are populated...
        # ...
    
    } elsif ( $fields[0] eq '' or $fields[1] eq '' ) {
        # One is populated...
        # ...

    } else {
        # Both are populated...
        # ...
    }
}

    It's important, though, that the subroutine not work on
external variables. Variables not passed into the sub.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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


Reply via email to