I don't have my Camel handy at the moment, but I believe the major issue with File::Temp occurs when you request only a filename, and not a handle, e.g. by setting OPEN=>0, because then you easily open yourself up to race conditions. IIRC, using the my ($filehandle, $filename) = tempfile(); form, even if all you do is immediately close $filehandle; and then use just the name, should be relatively safe if all the programs working in the temporary directory are well-behaved and the filesystem itself is well-behaved. (But make sure to read the entirety of the File::Temp docs.)

I'm a little confused about your code snippet, why do you open TIDY and then immediately close it again (without checking for errors, BTW)? tidy supports writing to and from files directly, which is what you appear to be doing, so it might be better to just use system instead of a piped open. Also, if you could explain what you are doing with the data before and after the tidy invocation, that would be helpful - e.g. what is $tempfile, do you need the data to reside in a regular file before and/or after the operation or do you just need it as strings in your program, etc. Depending on those requirements, it might be easier to just use IPC::Run3 (which does most of its work with temp files behind the scenes anyway). (I wrote at length about calling external commands here.)


In reply to Re: File::Temp::tempfile : name versus handle by haukex
in thread File::Temp::tempfile : name versus handle by mldvx4

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.