First, a succinct way to do this is to use the
between function from
Acme::Tools:
use Acme::Tools;
if (between($frequency, 10, 15) {print "Yes"}
I believe your code does not print Yes due to operator precedence. My guess is that
if ($frequency == 10 .. 15) {print "Yes"}
is the same as:
if ( ($frequency == 10) .. 15 ) {print "Yes"}
in which case, the left side of the .. operator
($frequency == 10) is false, and in that case the whole expression is false. Refer to
Range Operators.
Update: add another example...
If you set it to 10, you will get a Yes:
my $frequency = 10;
if ($frequency == 10 .. 15) {print "Yes"}
but, you will get a warning if you
use warnings; In any case, you should not try to use .. this way.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.