vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

while (<>) { print "$. $_" if 3 .. 10; }

The above code prints lines 3 to 10 of any input or file given to it. If we change it to "print "$. $_" if 3 ... 10;" it works the same way. How ?

Vinoth,G

Replies are listed 'Best First'.
Re: Range operators .. and ...
by lakshmananindia (Chaplain) on Apr 10, 2009 at 04:24 UTC

    Read about range operators in perlop

    .. will test both conditions on the first line that is examined. ... won't test the 'finish' condition on the first line.

    Example:

    begin a = b + 1 end begin j = k - 1 end

    /begin/ .. /end/ will identify the first 'end' as the finish condition, while /begin/ ... /end/ prevents checking for 'end' until a subsequent line is process. Hence, it finds the second occurance.

    I also suggest you to read Flipin good, or a total flop? tutorial

    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.