in reply to Re: Re: Range Operators Question
in thread Range Operators Question
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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(One Last)Re: Range Operators Question
by dsb (Chaplain) on Jul 19, 2001 at 02:16 UTC | |
by buckaduck (Chaplain) on Jul 19, 2001 at 02:38 UTC | |
by Hofmator (Curate) on Jul 19, 2001 at 15:11 UTC |