Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a temp filename in tcl?

503 views
Skip to first unread message

Phil Trubey

unread,
May 9, 1994, 12:46:23 PM5/9/94
to
Is there a way of creating a unique temporary filename in tcl?
I'm used to using the $$ construct from sh, but I can't seem to
find anything like that in TCL. Thanks!

Phil Trubey
ph...@netpart.com
--

Joe Moss

unread,
May 9, 1994, 5:16:51 PM5/9/94
to
ph...@lykos.netpart.com (Phil Trubey) writes:

>Is there a way of creating a unique temporary filename in tcl?
>I'm used to using the $$ construct from sh, but I can't seem to
>find anything like that in TCL. Thanks!

set tempfilename "prefix[pid]"

--
Joe V. Moss | j...@morton.rain.com
Morton & Associates | jo...@m2xenix.psg.com
7478 S.W. Coho Ct. | - or -
Tualatin, OR 97062-9277 | uunet!m2xenix!morton!joe

Thomas J. Accardo

unread,
May 9, 1994, 11:41:18 PM5/9/94
to
>Is there a way of creating a unique temporary filename in tcl?
>I'm used to using the $$ construct from sh, but I can't seem to
>find anything like that in TCL. Thanks!
>
>Phil Trubey
>ph...@netpart.com
>--

Well, you could make up some scheme for generating file names and
checking for uniqueness/existance. Maybe something like:

proc TempFile {prefix} {
set i 0
while {[file exists [set theFile ${prefix}_$i]]} {incr i}
return ${prefix}_$i
}
set tmpfile [TempFile /tmp/[pid]]

Or, maybe your system already has a command for doing it. Under
HP-UX, there's mktemp. It has a few options for specifying a
directory, prefix, etc., but it pretty much gets the job done
by just saying in Tcl:
set tmpfile [exec mktmp]

I honestly don't know if mktemp is some obscure HP-UXism, or if
its the most common command on the planet. The Tcl proc above
would probably be much faster (unless "i" if forced to grow large),
but the mktemp command is bit more flexible. Your choice...

Sincerely,
--------------------------------------
Thomas J. Accardo t...@cpu.com
Computerized Processes Unlimited, Inc.
Metairie, LA
Voice (504) 889-2784
FAX (504) 889-2799

Mumit Khan

unread,
May 11, 1994, 2:45:25 PM5/11/94
to

how about ``set tmpfile /tmp/[pid].tmp''

mumit -- kh...@xraylith.wisc.edu

0 new messages