I think what you're looking for is this:
You need to put the full comparison on each side of the range operator. Otherwise, you're doing something that's the equivalent of if ($string eq 'foo' || 'bar' || 'baz') {.foreach $i ( 0 .. 19 ) { if ($i == 5 .. $i == 10) { print "$i\n"; } }
There's one extra bit of info from perlop:
If either operand of scalar ".." is a constant expression, that operand is implicitly compared to the $. variable, the current line number.So your snippets are doing implicit comparisons against $.:
$i == (5 .. 10) compares $i to the result of the flip-flop, which flips when $. equals 5 and flops when $. equals 10.
$i == 5 .. 10 flips when $i equals 5 and flops when $. equals 10.
$i = (5 .. 10) assigns to $i the result of the flip-flop, which flips $. equals 5 and flops when $. equals 10.</code>
In reply to Re: Re: Re: Range Operators Question
by chipmunk
in thread Range Operators Question
by dsb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |