in reply to Re: Seeking and Printing
in thread Seeking and Printing

is there any way to do it with out the additional modules? there should be no problems with the domain not existing either.

Replies are listed 'Best First'.
Re: Re: Re: Seeking and Printing
by DamnDirtyApe (Curate) on Aug 14, 2002 at 18:21 UTC

    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
      Thanks very much for your time mate. That worked a treat. Big Up DamnDirtyApe! :-)