develooper Front page | perl.beginners | Postings from February 2002

Re: help to delete a line

Thread Previous
From:
John W. Krahn
Date:
February 27, 2002 13:09
Subject:
Re: help to delete a line
Message ID:
3C7D4B46.206D7801@acm.org
Joanne Fearon wrote:
> 
> Hi,

Hello,

> I have a file that I am chopping and changing. I want to delete line 12
> each time. I have a counter to tell the line number. Ive tried
> 
> if ($counter == 12)
>         {
>         next;
>         }
> $counter++
> 
> this doesn't give an error but doesnt move on to the next line either.


If you are reading from a file then the variable $. will contain the
current line number (explained in the perlvar document.)

while ( <FILE> ) {
    next if $. == 12;
    # do other stuff
    }


If you want to use your own counter then:

my $counter;
while ( <FILE> ) {
    next if ++$counter == 12;
    # do other stuff
    }


John
-- 
use Perl;
program
fulfillment

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About