开发者

cleaner way to unlink a File::Temp file?

开发者 https://www.devze.com 2023-01-30 22:03 出处:网络
I\'m currently doing this my $tmpf = File::Temp->new开发者_C百科; $tmpf->unlink_on_destroy(1);

I'm currently doing this

my $tmpf = File::Temp->new开发者_C百科;
$tmpf->unlink_on_destroy(1);

but it seems like this could be cleaner.. something like

my $tmpf = File::Temp->new({unlink => 1});

is something like the latter possible?


You can also set this flag in the constructor:

my $tmp = File::Temp->new( UNLINK => 1, SUFFIX => '.dat' );

But it is unnecessary. From the perldoc File::Temp:

by default the object is constructed as if tempfile was called without options, but with the additional behaviour that the temporary file is removed by the object destructor if UNLINK is set to true (the default).

0

精彩评论

暂无评论...
验证码 换一张
取 消