xenoterracide
xenoterracide

Reputation: 16855

cleaner way to unlink a File::Temp file?

I'm currently doing this

my $tmpf = File::Temp->new;
$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?

Upvotes: 1

Views: 1561

Answers (1)

Eugene Yarmash
Eugene Yarmash

Reputation: 149823

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).

Upvotes: 4

Related Questions