
- Forum
- Programming Talk
- Perl
- Unique File Names
Unique File Names
This is a discussion on Unique File Names within the Perl forums, part of the Programming Talk category; I am using $filename = "$$" . "$^T" . ".html"; to name my file for my Perl application. Will this ...
-
Unique File Names
I am using
$filename = "$$" . "$^T" . ".html";
to name my file for my Perl application. Will this always guarantee uniqueness of filename? If not how can I handle generally to name unique file names?
-
Yes this would ensure unique file name because in Perl the variable $$ denotes the process id that is used currently. In addition you have also used $^T which denotes current timestamp. So association of both these gives unique process id with current timestamp to filename making the filename as unique.
-
05-07-2007, 03:56 AM #3
- Join Date
- Apr 2006
- Answers
- 124
Sammy I agree that the variables denote current process id and the current timestamp making filename as unique. But there is a small thing here for consideration. The process ids are unique only up to a certain number. After it reaches the maximum number allowed there is possibility of the process id getting repeated again. Also attaching timestamp though makes it unique filename I feel it would give a bad shape to the filename.
-
02-24-2010, 06:12 AM #4
- Join Date
- Feb 2010
- Answers
- 4
Use the function tempfile() which is in the module File::Temp.
Example
use File::Temp qw/ tempfile tempdir /;
$fh = tempfile();
my ($fh, $filename) = tempfile();
print "file:$filename";
-
Sponsored Ads

Reply With Quote





