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
In reply to Range operator doesn't seem to work by Cristoforo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |