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


In reply to Range operator doesn't seem to work by Cristoforo

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.