in reply to Is "N" ge 90 && le 365 or does "N" = <string>?

The alphabetic comparison operators are for alphabetic comparison, the the symbol operators are for numeric comparison - just opposite of what the shell does.

Now, you might think that you can handle the situation like this:

if ($expire >= 90 && $expire <= 365 || $expire eq "never")
but there is a catch. If $expire is for instance "100 yellow ribbons", Perl will say hey, you are using $expire as a number, so I'll make it a number for you. Since it starts with 100, I'll pretent its value is 100.. This may, or may not be what you want. (With warnings on, Perl will issue a warning in this case, a warning you also get if $expire equal "never"). It's a more serious issue if the range you compare against includes 0, as a string that doesn't start with something that looks like a number will be considered to be 0 if used in numeric context.

So, write your condition as:

if ($expire =~ /^\d+$/ && $expire >= 90 && $expire <= 135 || $expire e +q "never")
You might want to modify the first clause if fractional values are to be accepted as well.

Abigail

Replies are listed 'Best First'.
Re: Re: Is "N" ge 90 && le 365 or does "N" = <string>?
by blink (Scribe) on Jan 30, 2004 at 00:58 UTC
    This is exactly what my confusion was. Thank you for your explanation! --S