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

Re: [FWP] Puzzle - Temp file creation



1999-07-14-23:52:41 Adam Sampson:
>[ re homebrew mktmp attempts ]
> However, the point I was trying to make was that you shouldn't do this
> anyway because there must be a module for it (lr@hpl.hp.com suggested
> POSIX::mktemp). Reinventing the wheel's not good (no matter how many ways
> there may be to do something).

Well, unless of course you should arrive at a way to do a broad category of
thing so sweeping that it kinda handily subsumes other more specialized
techniques.

While it's not perfectly the exact same problem as mktmp, I am wildly fond of
djb's unique-filename hack. So I could definitely see using

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

(_Boy_ do I wish I could just "IO::File->{RaiseError} = 1;". Maybe it's time
to take over maintenance responsibility and fork large tracts of the whole
perl module family, just to get out from under one famous and influential
p5per's hatred of exceptions).

Anyway, back to the point, until and unless we get systems that can wrap pids
in under a second, that is an idiom I find rewarding to keep in the toolbox;
and if it's sufficiently handy, it really takes the terror out of mktmping. If
you're finding other uses for it in a program, it might well make more sense
to just use it again than to use the separate, already-existing wheel.

-Bennett

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