xerophyte, this is a great place to start with learning perl. The tasks you wish to accomplish can be written (in a well structured manner, I know somebody will think of a one-liner method) in less than two dozen lines. The functions you need to use are very common ones which are well documented in ANY perl book (open, if, s///, system, print; to name a few).
However, I don't think anyone on here wants to write your program for you. First, you won't learn nearly as much if we write it for you. Second, only you know the specifics of your requirements. The desired question is one which includes at least a snippet of the code you have tried and any errors it produced. Most of the monks here are happy to help you along, but we do require that you put some real effort into solving the problem.
Finally, please take a shot at this yourself and post any problems you have then. When you re-post, please read this and specifically this first. | [reply] |
Learn Perl. Learn to use CPAN. You can roll your own codes, but most likely there's someone else that has done it already.
use strict;
use warnings;
use IO::File;
use DNS::ZoneParse;
my @zonefiles = </path/to/zonefile/*>;
foreach my $zonefile (@zonefiles) {
my $z = DNS::ZoneParse->new($zonefile);
# change ttl in all MX records, for example
my $mx = $z->mx;
$_->{ttl} = 'foo bar' for (@$mx); # update ttl
$z->new_serial();
# write the new zone file to disk
my $zf = new IO::File "$zonefile", "w"
or die "Error writing zonefile: $!";
print $zf $z->output();
}
| [reply] [d/l] |
If you're interested in a "fast" way, you may also want to at least give a glance to the -pi switch for calling the interpeter. Without giving away the plot, this will let you (if properly called ;) ) edit a series of files in place and create backups as you go. Sorta. (wiser monks will disagree on my verbage here, I'm sure).
"I have never written bad code. There are merely unanticipated features."
| [reply] |
it would be nice if someone can show me code which use the "use strict"
Ok, here you go:
use strict;
That wasn't too difficult, was it? Here's a question for you now: do you understand what it does?
| [reply] [d/l] |