in reply to Is it a list or a flip-flop?
Paladin has lucidly described the source of your error, but I notice there still seems to be some confusion about what the flip-flop operator actually does. Hopefully I can help clear the air a bit.
It's probably best to think of scalar .. and list .. as two completely different operators. You can sort of kind of see a connection between them, but what they do is different enough that it's confusing to think of both at once. I assume we all know what list .. does; it's the scalar version that is kind of confusing. But when you shake yourself free from the baggage of thinking about the range operator, it becomes a lot easier to understand.
The flip-flop is essentially a flag. It turns on, or off, depending on the two endpoints. The two endpoints are compared against something to determine whether or not to flip the flag on or off. If the first endpoint compares true, the flag is flipped on. If the second endpoint compares true, the flag is flipped off. This allows you to do some pretty useful things, such as get all the lines in a file between "BEGIN" and "END", or lines 2-24. Here are some (hopefully) clear examples:
my @lines = qw(foo BEGIN bar baz END qux); for (@lines) { if (/BEGIN/ .. /END/) { print "$_\n"; } } while (<DATA>) { if (3 .. 5) { print; } } __DATA__ Line one Line two The third and fourth what about the fifth? or the sixth?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it a list or a flip-flop?
by TimToady (Parson) on Aug 19, 2005 at 18:32 UTC |