Perl: the Markov chain saw | |
PerlMonks |
Why doesn't the flip-flop operator work in all scalar contexts?by siracusa (Friar) |
on Oct 02, 2008 at 12:51 UTC ( [id://714999]=perlquestion: print w/replies, xml ) | Need Help?? |
siracusa has asked for the wisdom of the Perl Monks concerning the following question: Why doesn't the flip-flop operator work in all scalar contexts? It works fine when looping over a file handle:
But it doesn't seem to work at all in other kinds of loops:
Both of those examples print the numbers 1 through 5, rather than skipping 1 and just printing 2 through 5. The docs for perl 5.10 don't seem to indicate that it only works in the context of file handles. From perldoc perlop: In scalar context, ".." returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ".." 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. It doesn't become false till the next time the range operator is evaluated. It just says "in scalar context," not "in scalar context if and only if you're looping over a file handle's records." Bad docs? Bad implementation? What am I missing?
Back to
Seekers of Perl Wisdom
|
|