in reply to Re: Perl script to comment out lines in named.con file
in thread Perl script to comment out lines in named.conf file

thanks for your help
put there isn't any way to edit in the file locally without making instance ? .
  • Comment on Re^2: Perl script to comment out lines in named.con file

Replies are listed 'Best First'.
Re^3: Perl script to comment out lines in named.con file
by GrandFather (Saint) on Oct 05, 2007 at 00:45 UTC

    You have to insert characters. Think about what that entails in terms of manipulating the file image on the hard disk. Every character after the inserted character has to be moved.

    There are modules like Tie::File which hide the details from you and expend a great amount of effort to make the process efficient, but at the end of the day every character in the file after the first character that is inserted has to be rewritten.


    Perl is environmentally friendly - it saves trees
      thanks iam going to check this module ..
      i think you saw the code that posted before your post
      #!/usr/bin/perl -w use strict; print " please enter the domain name: "; my $targetdomain = <STDIN>; chomp $targetdomain; my $file = "/home/blackice/hello"; open HAN,$file || die "error opening file: $!"; my $comment = 0; my $block = 0; while (<HAN>) { /^zone\s+"$targetdomain"/ and $comment++; if($comment) { $block += () = /(\{)/g; # add the number of { matches to $block s!^!// ! if $comment && $block; $block -= () = /(\})/g; # substract the number of } matches $comment = 0 unless $block; } print; }

      and my question is how i can make the effects appear in file by commenting the lines without printing it to shell .
      hey
      i think iam now very close to the right solution ..
      i write this
      #!/usr/bin/perl -w use strict; print " please enter the domain name: "; my $targetdomain = <STDIN>; chomp $targetdomain; my $file = "/home/blackice/hello"; open HAN,$file || die "error opening file: $!"; my @fileContent = <HAN>; close(HAN); for( my $i = 0; $i < @fileContent; $i++ ){ if( $fileContent[$i] =~ m/^zone\s+"$targetdomain"/ ){ $fileContent[$i] =~ s/\n/\n#/g; } } open HAN, ">$file"; print HAN @fileContent; close(HAN);

      after run the script th script only comment the second line
      #type master; only !
      and i want to comment all the lines and thanks for you help