in reply to Re^6: FEAR OF PERL
in thread FEAR OF PERL

i finally knows hot to do it :)
first i would to say perl is great language and all perl people are helpful and iam going to learn , learn and learn GOD willing
here is the code to make the whole task
#!/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/blackice/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 $comment = 0; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { print $out '// ' . $char; print $out ': ' . $susdate; $comment++; $block += () = /(\{)/g; print $out '// '.$_; next; } if($comment) { $block += () = /(\{)/g; s!^!// ! if $comment or $block; $block -= () = /(\})/g; $comment = 0 unless $block; } print $out $_; }

Thanks for all

Replies are listed 'Best First'.
Re^8: FEAR OF PERL
by TGI (Parson) on Oct 15, 2007 at 17:13 UTC

    Congratulations on modifying this script so that it meets your needs!

    Now take some time to comment the heck out of the script. Hit every line, and explain in plain language what it is you are doing and why.

    Now that you understand what all of the code is doing, is there anything redundant or broken in the code that should be removed or fixed?

    If I were reviewing this code, I would make these suggestions:

    • Add some comments.
    • use warnings.
    • Line 32 has a redundant condition in its if clause.
    • Use Perl's date functions instead of shelling out to `date` in line 9.
    • Use scalars in interpolated strings to simplify formatting of data. (Lines 24,25).

    It's clear that you are making progress. Keep up the good work and you will continue to build your skills.


    TGI says moo