[thelist] Perl: Writing to file not working......
CDitty
mail at redhotsweeps.com
Thu Aug 9 20:50:56 CDT 2001
Can someone take a look at this and see what is wrong? I am still
learning perl and this is giving me a tough time. If you can, please be
very specific as I am still learning and get confused easily lately. :)
The email.txt file is an empty file and has the correct permissions.
Thanks
Chris
# This section needs to cycle through the emails.txt file.
# Once it has cycled through the file completely,
# it needs to search the array? and see if the new email address
# is there. If it is, do nothing. If it is not, add it to the
# end of the file.
#Opens the counter file to get current number of plays
open (LOGEMAIL, "email.txt") || die "Can't open email.txt file for reading.";
flock (LOGEMAIL, 2); # Locks the file
@emailfile = <LOGEMAIL>; # Assigns the data from the file into an array
foreach $emailfile(@emailfile) { # Loops through for each record
($new_email) = split(/\|/, $logemailfile);
$new_email = lc($new_email); # lowercase
$email = lc($email); # lowercase
if('$new_email' eq '$email'){
last;
}
else{
$ok_to_log_email='1';
}
}
if($ok_to_log_email == '1'){
flock (LOGEMAIL, 8); # Unlocks the file
close(LOGEMAIL);
# Log the new player.
open (LOGEMAIL, ">>email.txt") || die "Can't open email.txt file.";
flock (LOGEMAIL, 2); # Locks the file
print LOGEMAIL "$email|\n"; # write to file
flock (LOGEMAIL, 8); # Unlocks the file
close(LOGEMAIL);
}
More information about the thelist
mailing list