As imp mentioned, this is behavior is documented. Unfortunately, the source code follows the docs. :-) I was hoping tempdir accepted a SUFFIX parameter just as tempfile does, but it does not (as of version 0.16).

If you really want your temp dir to have an extension, you could still use File::Temp but it would require a bit more work.

  1. Find all existing dirs in your base dir and create a file for them. For example, if the dir was named 'dir1234.mbox' you could create a file with the name 'temp_dir1234.mbox'.
  2. Use tempfile to create a new (unique) temp file in the base dir using the template 'temp_XXXXXXX' and SUFFIX 'mbox'.
  3. Since the existing directory names match the file names, you can create a directory named 'temp_XXXXXXX.mbox' (for whatever XXXXXXX is) and know it is unique. (If you were worried about race conditions you could check to see if it existed first.)
  4. When you're done with the temp dir and it is deleted, make sure you delete the corresponding file as well.

I'll be the first to say that the solution enumerated above is an ugly hack. If it were me, I'd use extensionless directory names or just check to see if it existed before I tried to create it. Do you really need the power of File::Temp for this? If you're not creating multiple temp dirs simultaneously this approach seems like overkill.


In reply to Re: tempdir with template fails by bobf
in thread tempdir with template fails by Skeeve

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.