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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |