On Tue, Jan 27, 2004 at 06:55:50PM -0800, Trina Espinoza ([EMAIL PROTECTED]) wrote:
> So this may be wishful thinking, but I would be kicking myself later if I didn't 
> ask. Is there a function in perl where you give
> the function  exact line numbers and it would only read the data in the range of 
> lines you gave it? My other alternative would be
> using a counter to find a start line and an end line in a file. Doable but painful. 
> Let me know if there is any hope . . . 

I did a "perldoc -f line" and didn't get any hits so I'm asuming not but
was curious so wrote the following function.  You might find it useful, you might
not.  You could use the slice "@lines[$begin..$end]" to do whatever action you wanted. 

#!/usr/bin/perl
use warnings;
use strict;

range(1,4);

sub range {
    my($begin, $end) = @_;
    my @lines;
    while(<DATA>) {
        push(@lines, $_);
    }
    print @lines[$begin..$end];
}
__DATA__
This is line one
This is line two
This is line three
This is line four
This is line five
This is line six
This is line seven
This is line eight

hth,
Kent

-- 
"Efficiency is intelligent laziness."
  -David Dunham

-- 
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