Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Using Temporary Files in Perl

by rob_au (Abbot)
on Jun 22, 2002 at 11:18 UTC ( #176476=note: print w/ replies, xml ) Need Help??


in reply to Using Temporary Files in Perl

Two new features has been incorporated into 5.8.0rc2 which allow for the creation and handling of temporary files in a secure manner. The first is the incorporation of means to create anonymous temporary files, similar to the unlinking of open files described above, without the need to make use of external modules via:

open( $fh, '+>', undef ) || die $!;

Where the undefined value is a literal undef statement, rather than an undefined variable. It should also be noted that the File::Temp module has now too been incorporated into the core distribution.

Another feature which allows for temporary file-type handling within code is that which allows for file handles to be opened into a memory space, via a scalar reference - For example:

open( $fh, '>', \$variable ) || die $!;

 


Comment on Re: Using Temporary Files in Perl
Select or Download Code
Re^2: Using Temporary Files in Perl
by jjosserand (Initiate) on Mar 30, 2015 at 15:29 UTC
    IMHO - use of tmp files; in an owner directory or the global /tmp directory should be an acceptable process IF... "$$" is used in the filename to isolate it from use by multiple processes doing the same thing. ...and... IF... no username nor password information is stored there. A question I have; however, is related to use of tmp files vs. variables. I was recently slapped around in email at work by a cohort reviewing some code I'd written that uses tmp files to parge svn merge output saved there to determine success or failure since 'die' wasn't sending data to stdout nor stderr apparently so could not be easily trapped and parsed. Can anyone give a brief tutorial of better use of vars as opposed to tmp files for such things? I'd really appreciate that.
      IF... "$$" is used in the filename to isolate it from use by multiple processes doing the same thing
      On shared filesystems, also include the machine name or IP/MAC address. I've encountered the $$ collision running a job on a 400+ nodes cluster.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://176476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2015-06-04 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What kind of chocolate gives you the most pleasure?















    Results (143 votes), past polls