Author: comdog
Date: Wed Jul 18 12:00:42 2007
New Revision: 9766
Modified:
perlfaq/trunk/perlfaq5.pod
Log:
* perlfaq5: How do I make a temporary file name?
+ fixed the code in the BEGIN. It was missing a ){, mostly
due to the prevailing but odd idea about where to put things.
Screw extra parens and legacy indention!
Modified: perlfaq/trunk/perlfaq5.pod
==============================================================================
--- perlfaq/trunk/perlfaq5.pod (original)
+++ perlfaq/trunk/perlfaq5.pod Wed Jul 18 12:00:42 2007
@@ -316,24 +316,25 @@
BEGIN {
use Fcntl;
my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMPDIR} || $ENV{TEMP};
- my $base_name = sprintf("%s/%d-%d-0000", $temp_dir, $$, time());
+ my $base_name = sprintf "%s/%d-%d-0000", $temp_dir, $$, time;
sub temp_file {
local *FH;
my $count = 0;
- until (defined(fileno(FH)) || $count++ > 100) {
- $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
- # O_EXCL is required for security reasons.
- sysopen(FH, $base_name, O_WRONLY|O_EXCL|O_CREAT);
+ until( defined(fileno(FH)) || $count++ > 100 ) {
+ $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
+ # O_EXCL is required for security reasons.
+ sysopen FH, $base_name, O_WRONLY|O_EXCL|O_CREAT;
+ }
+
+ if( defined fileno(FH) ) {
+ return (*FH, $base_name);
+ }
+ else {
+ return ();
+ }
}
-
- if (defined(fileno(FH))
- return (*FH, $base_name);
- }
- else {
- return ();
- }
- }
+
}
=head2 How can I manipulate fixed-record-length files?