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!

In reply to Re: querying a range of values by Marshall
in thread querying a range of values by plendid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.