I want to use truncate to delete a matched line out a named.conf file on
my DNS box.

Here is my code

 

use strict;

use warnings;

 

my $file = qq(/usr/local/admin/perl/derek_perl/test);

open (FH, "+< $file");

       while ( <FH> ) {

          unless (/\Acheck\-names/) {

              print $_;

          }

       }

 

The above code works as expected: perl myfile > foo

but can I use truncate as below:

 

 

use strict;

use warnings;

 

my $file = qq(/usr/local/admin/perl/derek_perl/test);

open (FH, "+< $file");

       while ( <FH> ) {

          if (/\Acheck\-names/) {

              my $addr=tell(FH);

              #print $addr,"\n";

              #print $_;

              truncate (FH, $addr);

 

          }

       }

 

The test files contains: 

 

check-names warn;

fooy;

 

I want to remove only the "check-names warn" line but the above code
removes all lines???

Any help?  Thank you

 

Derek Bellner Smith

Unix Systems Engineer

Cardinal Health Dublin, Ohio

614-757-5000 Main

614-757-8075 Direct

614-757-8120 Fax

[EMAIL PROTECTED]

 


Cardinal Health -- Working together. For life. (sm)
_________________________________________________

This message is for the designated recipient only and may contain privileged, 
proprietary, or otherwise private information. If you have received it in 
error, please notify the sender immediately and delete the original. Any other 
use of the email by you is prohibited.

Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk 
- Portuguese - Svenska: www.cardinalhealth.com/legal/email

Reply via email to