[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Puzzle - Temp file creation



1999-07-16-00:27:31 Bennett Todd:
> 	my($tmpfn1) = "/tmp/@{[time]}.${$}_@{[$n++]}.@{[hostname]}";
> 	my($tmpfh1) = IO::File->new($tmpseq,O_WRONLY|O_CREAT|O_EXCL)
> 		or die "$0: $tmpfn1: $!\n";

P.S. for the person who is worried about threads in the same process fighting,
wouldn't the natural fix be

	my($tmpfn1, $tmpfh1);
	$tmpfn1 = "/tmp/@{[time]}.${$}_@{[$n++]}.@{[hostname]}" until
		$tmpfh1 = IO::File->new($tmpseq,O_WRONLY|O_CREAT|O_EXCL);
	END { for ($tmpfn1) { unlink if defined and -f; } }

I've not yet done any threaded programming, but it seems to me like that would
be safe and robust. As long as /tmp isn't via NFS:-).

P.P.S. If of course I had my desperately-desired global RaiseError for all
syscall-involving functions, I'd of course have to rewrite that as

	$tmpfn1 = "/tmp/@{[time]}.${$}_@{[$n++]}.@{[hostname]}" until
	    eval { $tmpfh1 = IO::File->new($tmpseq,O_WRONLY|O_CREAT|O_EXCL); }

which wouldn't bother me in the least.

-Bennett

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe