- or download this
#!/usr/bin/perl -wi.bak
use strict;
- or download this
my %params;
my $filename = shift || die "Usage: netswap.pl CONFILENAME\n";
- or download this
open(FH,"$filename")
or die "Could not open network configuration file: [$filename] for
+ reading: $!\n";
- or download this
while(<FH>){
# Skip the blank lines or the commented lines
...
# avoid typing mistakes
$params{$name} = lc($value);
}
- or download this
print <<"EOL";
new hostname = [$params{hostname}]
...
new gateway = [$params{gateway}]
EOL
- or download this
my $replacements = {
'/etc/hosts' => {
...
my $replacements = shift;
foreach my $filename (keys %{$replacements}){
print STDERR "Processing file [$filename]\n";
- or download this
unless (-e $filename){
print STDERR " [$filename] cannot be found!\n";
next;
}
- or download this
@ARGV=($filename); # put the filename where perl can find it.
while(<>){
...
print STDERR " done\n";
}
}