Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Here Is The File:my $datafile = '/etc/postfix/virtual'; my $req_addr = "$username\@$domain"; my ( $name, $domain ) = $req_addr =~ /^([\w.-]+)(@[\w.-]+)$/ ; open FH, $datafile or die; my @virtual = <FH> ; close FH ; open FH, ">$datafile" or die; my $wrote_it = 0 ; for ( @virtual ) { print FH $_ ; if ( $_ =~ /$domain/ && !$wrote_it ) { print FH "$req_addr\t$username\n" ; $wrote_it++ ; } } close FH ;
I have the following variables $username which contains the users name (in this case idunno, or iknow), and $domain (in this case test.com or other.com).test.com VIRTUALDOMAIN #defines the domain name @test.com jnapier #defines the postmaster of domain idunno@test.com idunno #just a regular user other.com VIRTUALDOMAIN #defines the domain name @other.com jnapier #defines the postmaster of domain iknow@other.com iknow #just a regular user
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: There has got to be a Cleaner Way!
by FoxtrotUniform (Prior) on Aug 31, 2002 at 18:34 UTC | |
by jimbobn (Novice) on Aug 31, 2002 at 18:40 UTC | |
|
Re: There has got to be a Cleaner Way!
by Arien (Pilgrim) on Aug 31, 2002 at 19:05 UTC | |
|
Re: There has got to be a Cleaner Way!
by BrowserUk (Patriarch) on Sep 01, 2002 at 00:28 UTC | |
by jimbobn (Novice) on Sep 01, 2002 at 06:53 UTC |