SPUG: Two errors I need hashing out

Colin Meyer cmeyer at helvella.org
Tue Jan 15 12:37:00 CST 2002

On Tue, Jan 15, 2002 at 09:25:49AM -0800, Susanne Bullo wrote:
> Being new, I still haven't a complete clue as to what I'm doing.  The listed
> program is giving the following two errors:
> print on closed filehandle main::FILE at sunday line 61.
> DBD::mysql::st execute failed: Duplicate entry '127' for key 1 at sunday
> line 79.
> I'm at a loss as to what the first one is.  The second one I'm thinking has
> to do with number assigning within the database but I'm not completely sure
> (there is an id of 127 within the database but that is under id and not
> under uid which seems to be what "key 1" is referencing).

This sounds like MySQL is having trouble with some data in the table
you are selecting from.  If you are able to successfully prepare your handle
(which you are), and get an error when calling the execute() method on
the handle, then that indicates database trouble.  

My guess is that there are two records with the "unique" key value of
127.  Can you use another tool to look in your database and verify the
integrity of this table?

> my $filename = "$sec_file_path/$outfile";
> open (FILE,">>$filename");
> Line 61 -->{ print FILE "<a href=$sec_file_path>Problem on $date3</a>"; }
> close (FILE);
> }

Are you sure that your program was able to open the file successfully?
It is imperative to check for errors *every* time you open a file, or
close a file that has been written to. It may help to recode the above
lines to be more like:

  open FILE, ">>$filename" or die "Could not open file: $!";
  print FILE "...";
  close FILE or die "Could not write to file: $!";
  # we might not know of a write error (disk full, etc) until the 
  # filehandle is closed, causing buffers to be flushed.

Have fun,

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/

More information about the spug-list mailing list