in reply to IF Statement Testing

Several problems. First, <=> is a three-state operator. It has different return values for less than comparisons, greater than, and equal to. It's primarily used for numeric comparisons in sort routines. You should be using !=

The next problem is that you cannot chain 1||2||3||4||5 like that. That's like saying "If $expire is not equal to 1, or if two, or if three, or if four, etc." In other words, the comparison only binds to $expire != 1.

To write that correctly, the way you're trying to test, it would be:

if( $expire != 1 or $expire != 2 or $expire != 3...... )

...and so on. But how about this instead?

if( $expire != int $expire or $expire < 1 or $expire > 14 ) { die "Don't tamper with me!\n"; }

You could also do it like this, using a hash slice:

my %test; @test{ 1 .. 14 } = (); unless( exists $test{$expire} ) { die "Don't tamper with me!\n"; }

In all my examples, I've assumed that you want to reject non-integers.


Dave

Replies are listed 'Best First'.
Re^2: IF Statement Testing
by holli (Abbot) on May 14, 2005 at 10:38 UTC
    You flipped the logic here.
    if( $expire != 1 or $expire != 2 or $expire != 3...... )
    should be
    if( $expire != 1 and $expire != 2 and $expire != 3...... )
    OTOH, this can also be solved by a hash lookup


    holli, /regexed monk/