Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Unique filehandle -- what is correct?

by Perlbotics (Canon)
on Dec 11, 2011 at 11:37 UTC ( #942927=note: print w/ replies, xml ) Need Help??


in reply to Unique filehandle -- what is correct?

This is a common task, try a module like File::Temp. If you have perl 5.6.1 or newer, it is already installed. In your case, use UNLINK => 1 to automatically remove the temp. file after program execution. There are more options that let you fine-tune the filename format/suffix, the directory and so on.

use strict; use warnings; use File::Temp qw(tempfile); #-- UNLINK => 1: removes the tempfile when program finishes # perldoc File::Temp - shows more usage options my ($fh, $filename) = tempfile( UNLINK => 1); #-- that's it - now display filename... print "Filenme: $filename\n"; #-- or use filehandle... (here: no open()/close() required!) print $fh "lalala\n"; #-- here: file is removed automatically on program exit


Comment on Re: Unique filehandle -- what is correct?
Select or Download Code
Re^2: Unique filehandle -- what is correct?
by Anonymous Monk on Dec 11, 2011 at 12:32 UTC
    Yes it works ok! Now I can run multiple instances of the same cgi-script since it works with the temporary file each time!
    Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (18)
As of 2015-07-07 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (89 votes), past polls