BTW, I forgot a chomp... while( <INF> ) { chomp; ... same as before... } ----- Original Message ----- From: "Tanton Gibbs" <[EMAIL PROTECTED]> To: "Chris Zampese" <[EMAIL PROTECTED]>; "perl list" <[EMAIL PROTECTED]> Sent: Tuesday, January 29, 2002 9:22 PM Subject: Re: simple file question
> You can use the following > > open INF, "filename.txt" or die "Could not open file: $!\n"; > > my $myvar = <>; # get email address from stdin > my $found = 0; > > while( <INF> ) { > if( $myvar eq $_ ) { > $found = 1; > last; > } > } > > close(INF); > > if( !$found ) { > open OUTF, ">>filename.txt" or die "Could not open file for appending: > $!\n"; > print OUTF $myvar, "\n"; > } > > Naturally, there are many other ways to do it, many shorter than the above, > but I've tried to keep it simple and straightforward. > > Tanton > ----- Original Message ----- > From: "Chris Zampese" <[EMAIL PROTECTED]> > To: "perl list" <[EMAIL PROTECTED]> > Sent: Tuesday, January 29, 2002 9:10 PM > Subject: simple file question > > > Hello everyone, > I have a variable $myvar (an email address), and I would like to open a > simple text file which contains email addresses (one on each line) and check > to see if the address in $myvar is in there, if it is not, then append it o > the end of the file, and if it is, then close the file and carry on with the > rest of the script. > I have tried using while (<FILEHANDLE>){}, > but I am not really sure what to put in the brackets? > > Thanks as always, > Chris. > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]