From: Nicholas Clark Date: Thu, 7 Aug 2008 08:23:13 +0000 (+0000) Subject: A proper tempfile function that can be used multiple times. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1ddc35c47e1b3519bfe90eecd67145f73c0f30a;p=p5sagit%2Fp5-mst-13.2.git A proper tempfile function that can be used multiple times. p4raw-id: //depot/perl@34178 --- diff --git a/t/test.pl b/t/test.pl index 1259ed6..f0b4879 100644 --- a/t/test.pl +++ b/t/test.pl @@ -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