[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Puzzle - Temp file creation (HINTs)



I had one complaint about $TMPDIR (assume that $TMPDIR is a global defined
above "somewhere".)

If you don't like that, try it without $TMPDIR.  That removes one bug
(which? :-)

I have had one reply commenting that the object created by IO::File->new()
isn't saved anywhere. IO::File creates a file if successful, returning the
filehandle. One could argue that we have the filename and don't need the
filehandle... One could argue that there should be a comment to this effect.

Here's a little more wrapper code to give folks a better feeling about the
original:

sub call {

   my $db = shift;

   # find a suitable temporary name
   $target = "quickblast${$}aaaa";
   my $tries = 100;
   while (--$tries) {
     last if IO::File->new($target,O_WRONLY|O_EXCL|O_CREAT,0600);
     $target++;
   }
   return unless $tries;

   unlink $target;
   symlink($db,$target) || die "Couldn't symlink $db=>$target";

   ...
  return $target;
}

What's wrong with this code?



-- --
       |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
 ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
      |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
     '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.com

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe