Exforsys
+ Reply to Thread
Results 1 to 4 of 4

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 ...

  1. #1
    Angela is offline Member Array
    Join Date
    Apr 2006
    Answers
    85

    Thumbs up 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?


  2. #2
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    145
    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.


  3. #3
    Rahulbatra is offline Senior Member Array
    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.


  4. #4
    kiruthika_sri is offline Junior Member Array
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...