473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

The script is working well but i need to improve itis function .

hello all ...,

first i would thank all the people who are in this forums cause they are very helpful ...,

By the way i had some posts hers about comment out the named.conf file the script is simply comment out the zones in the file and it works well

while i was testing scrpt i found that the script is working in an fixed way which means that the zone must be 5 lines if it not a five line the script won't function as needed ., Here is teh script

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w 
  2.  
  3. use strict;
  4.  
  5. print " please enter the domain name: ";
  6.  
  7. my  $targetdomain =<STDIN> ;
  8.  
  9. chomp $targetdomain;
  10.  
  11. my  $file = "/home/adam/Desktop/hello";
  12.  
  13.  
  14. open HAN,$file || die "error opening file: $!";
  15.  
  16. my @lines =<HAN> ;
  17.  
  18. close(HAN);
  19.  
  20.  
  21.       foreach my $x ( 0 .. $#lines ){
  22.  
  23.  
  24. if( $lines [$x] =~ m/^zone\s+"$targetdomain"/ ){                     
  25.  
  26.             for my $n ( 0 .. 4 ) {
  27.  
  28.                 $lines[$x+$n] = "//" . $lines[$x+$n];
  29.  
  30.             }
  31.  
  32.            }
  33.  
  34.       }
  35.  
  36. open HAN, ">$file";
  37.  local   $" = "";
  38.  
  39. print HAN @lines;
  40.  
  41. close(HAN);
  42.  
as you saw the variable $n which is responsible for comments itis from (0 > 4)

i have tried many things

firt i have tried to make a variable which rally equals the last element

$v="}"; and i mae n from 0 .. $v and that failed

also i have tried to make another instance of the array like as i did in the first matching line

if( $lines [$y] =~ m/^};/ ){

and then make $n starts from 0 to the $lines [$]

any one can help me more and any help will be appreciated and thanks.
Oct 9 '07 #1
6 2293
i have done someting which is a condition if it find the }; it will break but the break didnot work and it had an error

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w 
  2.  
  3. use strict;
  4.  
  5. print " please enter the domain name: ";
  6.  
  7. my  $targetdomain = <STDIN>;
  8.  
  9. chomp $targetdomain;
  10.  
  11. my  $file = "/home/adam/Desktop/hello";
  12.  
  13.  
  14. open HAN,$file || die "error opening file: $!";
  15.  
  16. my @lines = <HAN> ;
  17.  
  18. close(HAN);
  19.  
  20.  
  21.       foreach my $x ( 0 .. $#lines ){
  22.  
  23.          if( $lines [$x] =~ m/^zone\s+"$targetdomain"/ ){
  24.  
  25.             for my $n (0 .. 9) {
  26.  
  27.                       if( $lines[$x+$n] =~ m/^\s};/ ){
  28.                             break ;                
  29.                 }
  30.  
  31.                 $lines[$x+$n] = "//" . $lines[$x+$n];
  32.  
  33.             }
  34.  
  35.          }
  36.  
  37.       }
  38.  
  39. open HAN, ">$file";
  40.  
  41. print HAN $_ for @lines;
  42.  
  43. close(HAN);
  44.  
when i run it it gives : \
Bareword "break" not allowed while "strict subs" in use at projectx.pl line 29.
Execution of projectx.pl aborted due to compilation errors.
Oct 9 '07 #2
numberwhun
3,509 Expert Mod 2GB
i have done someting which is a condition if it find the }; it will break but the break didnot work and it had an error

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w 
  2.  
  3. use strict;
  4.  
  5. print " please enter the domain name: ";
  6.  
  7. my  $targetdomain = <STDIN>;
  8.  
  9. chomp $targetdomain;
  10.  
  11. my  $file = "/home/adam/Desktop/hello";
  12.  
  13.  
  14. open HAN,$file || die "error opening file: $!";
  15.  
  16. my @lines = <HAN> ;
  17.  
  18. close(HAN);
  19.  
  20.  
  21.       foreach my $x ( 0 .. $#lines ){
  22.  
  23.          if( $lines [$x] =~ m/^zone\s+"$targetdomain"/ ){
  24.  
  25.             for my $n (0 .. 9) {
  26.  
  27.                       if( $lines[$x+$n] =~ m/^\s};/ ){
  28.                             break ;                
  29.                 }
  30.  
  31.                 $lines[$x+$n] = "//" . $lines[$x+$n];
  32.  
  33.             }
  34.  
  35.          }
  36.  
  37.       }
  38.  
  39. open HAN, ">$file";
  40.  
  41. print HAN $_ for @lines;
  42.  
  43. close(HAN);
  44.  
when i run it it gives : \
Bareword "break" not allowed while "strict subs" in use at projectx.pl line 29.
Execution of projectx.pl aborted due to compilation errors.
Please remember to add code tags around all code you post in the forums. You did it for your first post, but not your last one.

Thank you!

-Moderator
Oct 9 '07 #3
KevinADC
4,059 Expert 2GB
do you still need help with this question?
Oct 11 '07 #4
yes i need

i want to improve this script to not just comment a fixed length of the lines but i want to make it global so i asked in forums and i got that script that works wonderfully well .,

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. print " please enter the domain name: ";
  6.  
  7. my  $targetdomain = <STDIN>;
  8.  
  9. chomp $targetdomain;
  10.  
  11. my  $file = "/home/blackice/hello";
  12.  
  13. rename $file, "$file.bak" or die "Can't rename file '$file': $!\n";
  14.  
  15. open my $in, '<', "$file.bak" or die "Can't read file '$file': $!\n";
  16. open my $out, '>', $file or die "Can't write file '$file': $!\n";
  17.  
  18. my $comment = 0;
  19. my $block   = 0;
  20. while(<$in>) {
  21.     if (/^zone\s+"$targetdomain"/) {      
  22.     $comment++;
  23.         $block += () = /(\{)/g;            
  24.     print $out '// '.$_; next;
  25.     }
  26.     if($comment) {        
  27.     $block += () = /(\{)/g;
  28.         s!^!// ! if $comment or $block;
  29.         $block -= () = /(\})/g;
  30.         $comment = 0 unless $block;  
  31.     }
  32.     print $out $_;
  33. }
but i want to add some feature to this script i want to add the date at the top of the zone when that zone was commented on

i have tried to make some tries ,, i have created
my $date = `date -u "+%m/%d/%Y %H:%M:%S"`;
this is a date string that i can print in the script and i tried to print it here

print "date";
print $out $_;

also i have tried to print it before this line

print $out '// '.$_; next;

but it failed ,, i also have tried to print it in some other places and it also fails

so can you help me of how to think about that
Oct 14 '07 #5
KevinADC
4,059 Expert 2GB
my $date = `date -u "+%m/%d/%Y %H:%M:%S"`;

print "date";
print $out $date;
Oct 15 '07 #6
thanks it works thanks for your great support :)
Oct 15 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: paul | last post by:
My first php script involves logining in to a site. I used a tutorial from a book and it doesn't seem to be working correctly. The code is below I started with a simple form to insert a username...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
9
by: whitgurley | last post by:
I've searched the web as well as I can for a solution to this problem but have found nothing and just don't know enough about JavaScript to figure out what's going. What I'm trying to do is convert...
1
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
10
by: blackice | last post by:
Hello all this thread ihttp://www.thescripts.com/forum/thread50290.html contains what i need but i cannot understand some of the code i need more explain .... my $sampleinput = <<"EOF"; ...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
3
by: Gros Bedo | last post by:
Hello :-) I have a question about Python and Linux shell. I have a python program which is permanently resident in the end-user system. I'm currently producing a RPM package, and it works nicely....
0
by: Edwin.Madari | last post by:
here is a working code snippet to read from MySQL db. python tutorial has examples of reading from files. put them together to do your task. ===================================================...
5
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I am trying to get the DNS name of an arbitrary IP address on the network. If I use GetHostEntry as the documentation suggests I only get the name of the machine I am running the code on. All...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.