On Thu, Aug 09, 2001 at 06:53:15PM -0500, CDitty wrote:
> The email.txt file is an empty file and has the correct permissions.

You're reading from a file, expecting data to be there, but the file
is empty.  Could this be your problem?

 
> # 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

Please, use constants, not magic numbers.

    use Fcntl qw(LOCK_EX);
    flock(LOGEMAIL, LOCK_EX);

I'm assuming 2 is an exclusive lock.  I'm too lazy right now to go look it
up, which is my point about using constants.


> @emailfile = <LOGEMAIL>; # Assigns the data from the file into an array
>          foreach $emailfile(@emailfile) { # Loops through for each record

Don't read the file into an array and then iterate over it with foreach,
this could result in using up to twice as much memory as the file size.

           while ($emailfile = <LOGEMAIL>) {


>          ($new_email) = split(/\|/, $logemailfile);
>          $new_email = lc($new_email); # lowercase
>          $email = lc($email);         # lowercase

This is rather confusing.  You're splitting on |, but you only ever have one
value in the split list.  What's the point of adding the |?


> 
>          if('$new_email' eq '$email'){

This could very well be your problem.  You're comparing the literal strings
'$new_email' and '$email', which will never be equal.  Omit the quotes.


>                  last;
>          }
>          else{
>                  $ok_to_log_email='1';
>          }
> }
>          if($ok_to_log_email == '1'){

It's not necessary, but you should omit the quotes around 1; it can be
potentially confusing.


>          flock (LOGEMAIL, 8); # Unlocks the file

           use Fcntl qw(LOCK_UN);
           flock(LOGEMAIL, LOCK_UN);

You can omit it altogether, as the close will unlock 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);
>          }

It might be a better idea to open email.txt with a mode of +<, i.e.
open(LOGEMAIL, "+<email.txt"), thus only requiring one lock, unlock, and
close.


Hopefully something in the above helped fix your problem.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to