in reply to Re^3: Deleting lines from named.conf file
in thread Deleting lines from named.conf file
i just want to provide some of what i think about my program#the first part of the code as the same last code i provided #!/usr/bin/perl -w use strict; print " please enter the domain name: "; my $targetdomain = <STDIN>; my $susdate = `date -u "+%m/%d/%Y %H:%M"`; my $char = "This Domain is Suspended at "; chomp $targetdomain; my $file = "/home/adam/Desktop/hello"; rename $file, "$file.bak" or die "Can't rename file '$file': $!\n"; open my $in, '<', "$file.bak" or die "Can't read file '$file': $!\n"; open my $out, '>', $file or die "Can't write file '$file': $!\n"; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { #here i want to start to deleting lines i think it will done by s// /; #by replacing the lines with an empty lines #then i need to increase the $block by 1 to add the first #open bracke +t by using $block += () = /(\{)/g; #then i want to make something like condition if the block #variable i +s exist add one also to block and then continue #deleting lines if ($block) { s// /; #or if it find a closed bracket decrease the $block by $block -= () = /(\})/g; #and if the block equal to 0 stop deleting lines #then print the output
i think it may need a loop to loop throw target domain zone and then delete the files from the zone header to the end of zonemy $comment = 0; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { $comment++; $block += () = /(\{)/g; # print $out '// '.$_; next; } if($comment) { $block += () = /(\{)/g; s!^!// ! if $comment or $block; $block -= () = /(\})/g; $comment = 0 unless $block; } print $out $_ unless $comment; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Deleting lines from named.conf file
by shmem (Chancellor) on Nov 10, 2007 at 21:52 UTC | |
by firewall00 (Acolyte) on Nov 10, 2007 at 22:37 UTC | |
by shmem (Chancellor) on Nov 10, 2007 at 23:32 UTC | |
by firewall00 (Acolyte) on Nov 11, 2007 at 00:05 UTC | |
by shmem (Chancellor) on Nov 11, 2007 at 00:21 UTC | |
|