Hello monks
finally i made that code which is really a code, to comment out the named.conf file
by choosing the domain name and then it will make matching and provide a counter, which is actually to put the comment from the matched line and till 5 five line starting form this matched line
so here is the code
#!/usr/bin/perl -w
use strict;
print " please enter the domain name: ";
my $targetdomain =<STDIN> ;
chomp $targetdomain;
my $file = "/home/adam/Desktop/hello";
open HAN,$file || die "error opening file: $!";
my @array =<HAN> ;
close(HAN);
foreach my $x ( 0 .. $#array ){
if( $array[$x] =~ m/^zone\s+"$targetdomain"/ ){
for my $n (0 .. 4) {
$array[$x+$n] = "//" . $array[$x+$n];
}
}
}
open HAN, ">$file";
print HAN "@array";
close(HAN);
it works fine for the first time but i noticed somthing which make me confused
every time i run this script on the file the file it shifted one space from the left like that
this is the status of the file before running the script .
zone "domain.com"
type master;
file "/path/to/zone/domain.com";
notify yes;
};
zone "mydomain.com" {
type master
file "/path/to/zone/mydomain.com";
notify yes
};
zone "do.com" {
type master;
file "/path/to/zone/do.com";
notify yes;
};
and after running it
zone "domain.com"
type master;
file "/path/to/zone/domain.com";
notify yes;
};
//zone "mydomain.com" {
//type master
//file "/path/to/zone/mydomain.com";
//notify yes
//};
zone "do.com" {
type master;
file "/path/to/zone/do.com";
notify yes;
};
the script comment out the zone as i nedded but, you see the space added the left of the file and after run it again the spac is increased by one and so on . .
how can i prevent such space. that is must for my code to keep the file without any changes and without any spaces . and just comment the nedded zones .
thanks MonKs
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.