I might be wrong but I don't think you can. The range operator
- applies to ranges of characters (including numbers), not a range of numbers (unless the numbers are below 10). See
perlre.
use strict;
use warnings;
while (my $line = <DATA>) {
my $match = 0;
chomp $line;
if ($line =~ m/^X\((\d+)\)Y\((\d+)\)$/) {
$match = 1 if ( $1 >= 0
&& $1 <= 35
&& $2 >= 22
&& $2 <= 50);
}
($match) ? print $line . q{ match} : print $line . q{ miss};
}
__DATA__
X(0)Y(35)
X(21)Y(49)
X(55)Y(55)
X(-1)Y(33)
$ perl -l 650946.pl
X(0)Y(35) match
X(21)Y(49) match
X(55)Y(55) miss
X(-1)Y(33) miss
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.