Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: running same bit of code twice
by pfaut (Priest) on May 04, 2003 at 17:45 UTC | |
by jonnyfolk (Vicar) on May 04, 2003 at 18:30 UTC | |
by belg4mit (Prior) on May 04, 2003 at 18:43 UTC | |
by Anonymous Monk on May 04, 2003 at 17:57 UTC | |
by The Mad Hatter (Priest) on May 04, 2003 at 18:09 UTC | |
by Anonymous Monk on May 04, 2003 at 18:13 UTC | |
|
Re: running same bit of code twice
by chromatic (Archbishop) on May 04, 2003 at 23:29 UTC |