Trina Espinoza 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?

You can use integer literals with the range operator in scalar context:

while ( <FILE> ) {
    if ( 44 .. 98 ) {
        # do something only to lines 44 through 98 inclusive
        }
    }


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

You can use the built-in $. variable which contains the current line number:

my ( $start, $end ) = @ARGV; # get line numbers from the command line
while ( <FILE> ) {
    if ( $. == $start .. $. == $end ) {
        # do something only to line numbers in $start through $end inclusive
        }
    if ( $. == 73 ) {
        # do something only to line 73
        }
    }


Note that $. only works when reading a filehandle in a while loop.


John
-- 
use Perl;
program
fulfillment

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