[sf-perl] Bad file number

Joe Brenner doom at kzsu.stanford.edu
Sat Jun 23 16:01:00 PDT 2007

Steve Fink <sphink at gmail.com> wrote:

> (And by the way, most of the reasons you list for close() failing
> wouldn't actually cause it to fail. Not on a Unix-like platform, at
> least. You're mixing up closing a file descriptor with "closing a
> file" or "closing a directory entry" or something.)

Yes, it does seem that in the following case (where the file
is deleted in the middle of writing to it) there's no failure
on close:

  my $file = "/mnt/floppy/testy.txt";  
  my ($fh, $count, $dot_count);

  open $fh, ">", $file or die "couldn't open $file: $!";

  for my $count (0 .. 2000) {
    print {$fh} "$count\n";
    if ($count == 1000) {
      system("rm $file");
  close( $fh ) or die "Couldn't CLOSE $file: $!";

Though on the other hand, this case (filling up the disk 
to the point where print fails, and then trying to do a close)
definitely does fail:

   open $fh, ">", $file or die "couldn't open $file: $!";
   $count = 0;
   while( 1 ) {
     print {$fh} "$count\n" or last STRAW;
   close( $fh ) or die "Couldn't CLOSE $file: $!";

  # Can't close(GLOB(0x504160)): No space left on device at (eval 4) line 3
  	main::__ANON__('GLOB(0x504160)') called at /home/doom/bin/testes-fill_er_up line 56

(Note: on a linux box, using a floppy disk formated with ext2.)

More information about the SanFrancisco-pm mailing list