jeudi 14 mars 2019

Perl string if/or comparison operator

Why is the following code:

# Get new_status
print STDERR "Please enter status value (active/inactive): ";
ReadMode(1);
my $new_status = ReadLine(0);
ReadMode(0);
print STDERR "\n";

if ( ($new_status ne "active") || ($new_status ne "inactive") )
{
  die "Status must be active/inactive.";
}

will always return "Status must be active/inactive." no matter what I type? (active, inactive, or anything else, or even just press enter.)

The code appears to be valid:

  • I clearly separate both statement with brackets
  • I use the string operator "ne" in both cases
  • I use the OR operator ||

There's obviously something about Perl operators I am not fully grasping. What am I doing wrong?

Thank you !

Aucun commentaire:

Enregistrer un commentaire