At 9:56 am -0500 2/2/01, Chris Nandor wrote:

|   Also note this opens the file in the current working directory.  I
|   sometimes prefer something like:
|   
|   use File::Spec::Functions qw(:DEFAULT tmpdir);
|   use Symbol;
|   $fh = gensym;
|   do { $name = catdir(tmpdir, tmpnam) }
|      until ! -e $name && open $fh, "+> $name";
|   
|   That should open it in the $ENV{TMPDIR} or whatever, which should be at
|   HD:Temporary Items: by default.

Yes, but in perl, unlike Applescript (where 'path to temporary items' creates the 
directory), you have to do a mkdir to ensure it exists

|   >$fh->autoflush(1);
|   
|   $fh is no longer an object, so:
|   
|   select((select($fh), $|++)[0]);

Since I'm still working with a slow machine I prefer to avoid loading libraries, 
especially such monsters a POSIX, for simple tasks.  Besides, I like home-grown 
routines.  The method below needs no imports and is swift, though it would need 
modification if there were a possibility of 27 files being created in a second.  I'm 
happy to have it torn to shreds by more experienced perlers - as a beginner I find 
that a good way to learn.

     #!perl -w
     @az = split //,"abcdefghijklmnopqrstuvwxyz";
     $tmpdir = $ENV{TMPDIR};
     mkdir $tmpdir, 0;
     
     for ($i=0; $i<100; $i++) {
       maketemp ();
     }
     opendir DIR, $tmpdir;
     @flist = readdir DIR;
     foreach (@flist){ print "$_$/" ; unlink "$tmpdir$_";}
     
     sub maketemp{
       $f =  'tmp' .(substr time, -5, 5) . shift @az;
       $#az < 0 and @az = split //, "abcdefghijklmnopqrstuvwxyz";
       $tmp = "$tmpdir$f";
       open TMP, ">$tmp" or die $!;
       close TMP;}





Reply via email to