in reply to querying a range of values

The right way to decide if some value is between say 10 and 15 is to use 2 compares and "AND" the result together. The value must be >=10 AND <=15. Below I used the && operator instead of "and" which would have worked also. There is a difference in precedence between these 2 operators either one will work with the statement as I have written it.

In order to get your code to print "Yes", I set $frequency = 10. This winds up meaning: "if ($frequency == 10 ...some not understandable stuff, hence the error message)".

The "==" operator means exactly "equal to".

I recommend always enabling warnings, either by the "shebang line" #!/usr/bin/perl -w or the statement "use warnings;". "use strict" is also an extremely good idea.

You would have seen immediately that Perl didn't like your "if" statement.

#!/usr/bin/perl -w use strict; my $frequency = 10; if ($frequency == 10 .. 15) #this is line 5 {print "Yes freq 10 is ok!(or maybe not quite right!)"} print "\n"; $frequency = 12; if ( (10 <= $frequency) && ($frequency <=15 ) ) { print "Yes $frequency is ok!\n"; } __END__ prints: Use of uninitialized value $frequency in range (or flop) at C:\TEMP\compare.pl line 5. Yes freq 10 is ok!(or maybe not quite right!) Yes 12 is ok!

Replies are listed 'Best First'.
Re^2: querying a range of values
by plendid (Sexton) on Jan 13, 2010 at 12:24 UTC

    Nicely done. Thank you all for advice and insight.

    I think that i'll opt for smart quotes for now.