Hello Monks
I don't understand why the following code won't accept a value within the range specified. It dies even when values that should be valid are given. Thanks for any light you may shed on this
Chris
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
my $usage = "Usage; $0 [-t x] where x is
a time interval in minutes from 10 to 60.
If no interval is given, defaults to 1 hour (60 min).\n";
my %opts;
getopts ('t:',\%opts);
my $interval = $opts{t} || 60;
die $usage unless $interval == 10 .. $interval == 60;
Update:
Thank you for your helpful answers. I have read perlop (probably not closely enough :-) ). I was looking at some old code snippets i kept around and thought that one of them did what I was first attempting
for my $i (1 .. 15) {
if(my $cnt = $i==5 ... $i==10) {
print "$i - $cnt\n";
}
}
prints
C:\perlp>range_op.pl
5 - 1
6 - 2
7 - 3
8 - 4
9 - 5
10 - 6E0
I think in this example it becomes true when $==5 and then becomes false when $i==10. Just some fuzzy thinking on my part. I guess neniro's example is the one that will work for me. Thanks again Chris
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|