Yes, though Tie::File isn't really an "additional module," since it's now part of the 5.8.0 distribution. Here's how you could do it w/o Tie::File:
#! /usr/bin/perl
use strict ;
use warnings ;
$|++ ;
my $datafile = 'test_a.dat' ;
my $username = 'terry' ;
my $req_addr = 'tag@foo.com' ;
my ( $name, $domain ) = $req_addr =~ /^([\w.-]+)(@[\w.-]+)$/ ;
open FH, $datafile or die "Couldn't read $datafile: $!" ;
my @virtual = <FH> ;
close FH ;
open FH, ">$datafile" or die "Couldn't write $datafile: $!" ;
my $wrote_it = 0 ;
for ( @virtual )
{
print FH $_ ;
if ( $_ =~ /$domain/ && !$wrote_it )
{
print FH "$req_addr\t$username\n" ;
$wrote_it++ ;
}
}
close FH ;
__END__
_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
--Friedrich Nietzsche
|