On Mon, Jun 04, 2001 at 11:40:46PM -0500, [EMAIL PROTECTED] wrote:
> } elsif ( $remtag == "1" ) {
> $remove_email = $formdata{rem_name};
> open(FILE, "$filename");
Always check your open calls. For example:
open(FILE, $filename) || die("Unable to open file \"$filename\": \l$!.\n");
or perhaps, if you're in a loop:
unless (open(FILE, $filename)) {
warn("...");
next;
}
> while (<FILE>) {
> @fields = split(/\@/, $_);
> if ( $fields[0] ne $remove_email ) {
> open(NEWFILE, ">>$tmpfile");
Another open to check.
> print NEWFILE "$_";
> close(NEWFILE)
> }
> }
> close(FILE);
> }
You should move your open(NEWFILE, ...) call outside of the while loop, and
thus reduce the number of open calls made.
open(NEWFILE, ">>$tmpfile") || die("...");
while (<FILE>) {
...
if (...) {
...
print NEWFILE $_;
}
}
close(NEWFILE);
close(FILE);
Odds are that at least one line from $filename will not match, so the open
isn't wasted.
> the file loops through a couple times causing multiples of lines from
> $filename to be written to $tmpfile. can someone point out my error?
As it stands, your code runs fine. When I run it I get a temp file
consisting of the lines I expect, with no duplicates. Perhaps the problem
lies in your data, or in some portion of the code outside of the one you
gave us.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--