Peeps
The following bit of code edits the postfix file, and searches for a domain name. I have 2 domains in the file, but in order to edit the the data for the 2 domaisn in the file, i am running the same code twice, is there a better way to do this using loops or better?
my $req_addr = 'bob@domain1.com';
my ( $name, $domain ) = $req_addr =~ /^([\w.-]+)(@[\w.-]+)$/ ;
open FH, $datafile or die "Could Not Read Virtual File" ;
my @virtual = <FH> ;
close FH ;
open FH, ">$datafile" or die "Could Not Write Virtual File" ;
my $wrote_it = 0 ;
for ( @virtual )
{
print FH $_ ;
if ( $_ =~ /domain1.com/ && !$wrote_it )
{
print FH "$req_addr\t$username\n" ;
$wrote_it++ ;
}
}
close FH ;
my $req_addr = 'bob@domain2.com';
my ( $name, $domain ) = $req_addr =~ /^([\w.-]+)(@[\w.-]+)$/ ;
open FH, $datafile or die "Could Not Read Virtual File" ;
my @virtual = <FH> ;
close FH ;
open FH, ">$datafile" or die "Could Not Write Virtual File" ;
my $wrote_it = 0 ;
for ( @virtual )
{
print FH $_ ;
if ( $_ =~ /domain2.com/ && !$wrote_it )
{
print FH "$req_addr\t$username\n" ;
$wrote_it++ ;
}
}
close FH ;