When next is applied, you jump to the next iteration (read a new line) without incrementing your $count. So its value is always 0.
Instead of count, you could use the special var $., which is the current line number. And then, there is an operator that has the "from".."to" semantic in perl, it is the .. or flip flop operator. You can use it like that:
while (<DATA>)
{
if (condition1..condition2)
{
# Here only the line from the moment condition1 is true, until con
+dition2 is reached are processed
}
}
And the flip flop operator happens to have a bit of DWIM magic, that makes it check the line number (ie $.) if instead of conditions you use numbers:
while (<DATA>)
{
next unless 3..7; # ignore all lines except between 3 and 7 include
+d
print;
}
__DATA__
One
Two
Three
Four
Five
Six
Seven
Eight
Nine
|