develooper Front page | perl.cvs.perlfaq | Postings from July 2007

[svn:perlfaq] r9766 - perlfaq/trunk

From:
comdog
Date:
July 18, 2007 12:00
Subject:
[svn:perlfaq] r9766 - perlfaq/trunk
Message ID:
20070718190042.DA5FDCB9E1@x12.develooper.com
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?



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About