diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-08-07 08:23:13 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-08-07 08:23:13 +0000 |
commit | c1ddc35c47e1b3519bfe90eecd67145f73c0f30a (patch) | |
tree | d4136f1cf17652df6f3bd4826f7a125b14dbb886 /t/test.pl | |
parent | 0ae187c2299ef45fea08a054a5af0902048b539e (diff) | |
download | perl-c1ddc35c47e1b3519bfe90eecd67145f73c0f30a.tar.gz |
A proper tempfile function that can be used multiple times.
p4raw-id: //depot/perl@34178
Diffstat (limited to 't/test.pl')
-rw-r--r-- | t/test.pl | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -619,6 +619,9 @@ sub unlink_all { } } +my @tmpfiles; +END { unlink_all @tmpfiles } + # Avoid ++, avoid ranges, avoid split // my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z); sub tempfile { @@ -630,14 +633,18 @@ sub tempfile { $try .= $letters[$temp % 26]; $count = int ($temp / 26); } while $temp; - return $try unless -e $try; + if (!-e $try) { + # We have a winner + push @tmpfiles, $try; + return $try; + } $count = $count + 1; } while $count < 26 * 26; die "Can't find temporary file name starting 'tmp$$'"; } +# This is the temporary file for _fresh_perl my $tmpfile = tempfile(); -END { unlink_all $tmpfile } # # _fresh_perl |