Methods for creating unique file name? 
Author Message
 Methods for creating unique file name?

Who has a good routine for creating unique filenames in Perl5 and 4?

--
C. Christian Brink,CNE
IS-Manager
All-Sports Supply, LLC
Clackamas,OR





Fri, 22 Dec 2000 03:00:00 GMT  
 Methods for creating unique file name?

: Who has a good routine for creating unique filenames in Perl5 and 4?

POSIX::tmpnam()
IO::File::new_tmpfile()

The first actually returns a name, but doesn't open the file; the second
opens a unique temp file for read/write, but doesn't show you the name.

Both are Perl5 only, of course.  I believe you'd have to roll your own
Perl4 solution.

---------------------------------------------------------------------

 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/  
       "Every man and every woman is a star."



Fri, 22 Dec 2000 03:00:00 GMT  
 Methods for creating unique file name?

Quote:

> Who has a good routine for creating unique filenames in Perl5 and 4?

If you have a filename and you want to make sure that there is not an
already-existing file with that name, then try this:

$filename = "myfile";

$max_length = 31; # set this for your OS;

if (-e $filename) {

  substr($filename, (length $filename) - 1, 1)++ while -e $filename;

Quote:
}

THIS IS UNTESTED CODE.

--
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.



Sat, 23 Dec 2000 03:00:00 GMT  
 Methods for creating unique file name?

Quote:


}> Who has a good routine for creating unique filenames in Perl5 and 4?
}If you have a filename and you want to make sure that there is not an
}already-existing file with that name, then try this:
}$filename = "myfile";
}$max_length = 31; # set this for your OS;
}if (-e $filename) {

}  substr($filename, (length $filename) - 1, 1)++ while -e $filename;
}}
}THIS IS UNTESTED CODE.

This seems to have a pretty serious race condition.  Multiple
copies of this program could all get the same filename.

--



Sat, 23 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. unique file name

2. unique file name

3. finding unique file names?

4. Create unique file in dir?

5. Creating a variable with a file path/name in it

6. how to create name for temporary file

7. Creating Arrays from a file of names

8. Creating unique filenames by sequence

9. How do I create a unique (reproducible) identifier?

10. creating unique session id w/ perl

11. Creating a unique id number?

12. creating unique numbers/strings

 

 
Powered by phpBB® Forum Software