Range Operators
The .. range operator is really two different operators depending on the
context.
In scalar context, .. returns a
Boolean value. The operator is bi-stable, like an electronic flip-flop,
and emulates the line-range (comma) operator of sed,
awk, and various editors. Each scalar .. operator maintains its own Boolean state. It
is false as long as its left operand is false. Once the left operand is
true, the range operator stays true until the right operand is true,
after which the range operator becomes false again.
The operator doesn’t become false until the next time it is evaluated. It
can test the right operand and become false on the same evaluation as the
one where it became true (the way awk’s range
operator behaves), but it still returns true once. If you don’t want it to
test the right operand until the next evaluation (which is how
sed’s range operator works), just use three dots
(...) instead of two.[65] With both .. and ..., the right operand is not evaluated while
the operator is in the false state, and the left operand is not evaluated
while the operator is in the true state.
The value returned is either the null string for false or a sequence
number (beginning with 1) for true. The
sequence number is reset for each range encountered. The final sequence
number in a range has the string “E0” appended to it, which doesn’t affect its numeric value, but gives you something to search for if you want to exclude the endpoint. You can exclude the beginning point ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access