new#
Construct a File::Temp object wrapping a newly created temporary file.
תקציר#
my $tmp = File::Temp->new;
my $tmp = File::Temp->new(TEMPLATE => 'dataXXXXXX', DIR => '/var/tmp', SUFFIX => '.dat');
מה מוחזר#
A blessed object that acts as an open read/write filehandle. It stringifies to its filename and numifies to refaddr. The underlying file is unlinked when the object is destroyed, unless you opt out with UNLINK => 0.
Options#
Same as tempfile, with two differences: UNLINK defaults to true and OPEN is always on. Pass TEMPLATE => 'nameXXXXXX' to control the filename pattern.
דוגמאות#
use File::Temp;
my $tmp = File::Temp->new(SUFFIX => '.json');
print $tmp qq({"ok":1}\n);
my $path = $tmp->filename; # /tmp/XXXXXXX.json
my $tmp = File::Temp->new(UNLINK => 0); # keep the file after exit
מקרי קצה#
OPEN => 0is silently ignored; the file is always opened.Object destruction while
$File::Temp::KEEP_ALLis true skips unlink.
הבדלים מן ה-upstream#
Fully compatible with upstream File::Temp 0.2312.
ראו גם#
tempfile- functional counterpart returning($fh, $filename).File::Temp->newdir- directory constructor.filename- retrieve the pathname without stringifying.unlink_on_destroy- toggle the unlink-on-destruction flag.