in reply to Re: Re: Seeking and Printing
in thread Seeking and Printing
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__
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Seeking and Printing
by jimbobn (Novice) on Aug 14, 2002 at 19:15 UTC |