On Jan 30, Randy W. Sims said:

>On 01/30/04 03:59, John W. Krahn wrote:
>> "Randy W. Sims" wrote:
>>
>>>while (<>) {
>>>   if ( $start_line .. $end_line ) {
>>
>> That will be true if $start_line is true and false if $start_line is
>> false.  The value in $end_line is irrelevant.
>
>perl -lne 'print if 10..20' some_file
>
>prints lines 10-20. See the perlop manpage.

Re-read it.  Using .. that way ONLY WORKS if its arguments are constants.

  while (<FOO>) {
    print if 5 .. 10;  # print lines 5-10
  }

Compare that with

  ($x, $y) = (5, 10);
  while (<OO>) {
    print if $x .. $y;  # prints all the lines
  }

If you're using variables, you'll need to compare to $. explicitly.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to