You might check out how the CGI module implements temp-files. It takes things a step further and unlinks the file after an open() wich makes it harder for another process to intercept the file handle.

But that's exactly what open my $fh, "+>", undef does. (Under osen that permit it.)

stout:~ [16:28:32]$ strace -eopen,unlink perl -e 'open $f, "+>", undef +' open("/etc/ld.so.preload", O_RDONLY) = 3 open("/etc/ld.so.cache", O_RDONLY) = 3 open("/lib/libpthread.so.0", O_RDONLY) = 3 open("/lib/libnsl.so.1", O_RDONLY) = 3 open("/lib/libdl.so.2", O_RDONLY) = 3 open("/lib/libm.so.6", O_RDONLY) = 3 open("/lib/libcrypt.so.1", O_RDONLY) = 3 open("/lib/libutil.so.1", O_RDONLY) = 3 open("/lib/libc.so.6", O_RDONLY) = 3 open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3 open("/dev/null", O_RDONLY|O_LARGEFILE) = 3 open("/tmp/PerlIO_dr5fu4", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = +3 unlink("/tmp/PerlIO_dr5fu4") = 0 Process 17389 detached

Also see:

stout:~ [16:29:17]$ perl -le 'open $f, "+>", undef; system "ls -l /pro +c/$$/fd"' total 5 lrwx------ 1 blazar users 64 Dec 6 16:29 0 -> /dev/pts/0 lrwx------ 1 blazar users 64 Dec 6 16:29 1 -> /dev/pts/0 lrwx------ 1 blazar users 64 Dec 6 16:29 2 -> /dev/pts/0 lrwx------ 1 blazar users 64 Dec 6 16:29 3 -> /tmp/.nfs00364089000002 +21 lr-x------ 1 blazar users 64 Dec 6 16:29 4 -> pipe:[12410097]

(That's because /tmp is nfs mounted here, under other fs's it would explicitly tell you it has been deleted - at least IIRC it did when I tried it.)


In reply to Re^2: Safe Temp Files by blazar
in thread Safe Temp Files by gmock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.