Re: I am getting flooded with tmp files
[email protected] (Peter Scott)
| Newsgroups | perl.perl6.users |
|---|---|
| Message-ID | <[email protected]> |
Something in your program is keeping them open until your program closes
the filehandles on exit. Unlink can't remove a file that's open, only
make a note for later. Restricting the scope of the temp file handles
would probably be the cleanest way.
On 11/18/2024 8:49 PM, ToddAndMargo via perl6-users wrote:
> On 11/18/24 20:06, ToddAndMargo via perl6-users wrote:
>> I am getting flooded with tmp files. I though
>> I was erasing them (unlink). What am I doing
>> wrong:
>>
>> use File::Temp;
>> ...
>> my Str $TmpFile = $?FILE;
>> $TmpFile ~~ s| .* $( Q[/] ) ||; # we need just the name
>> $TmpFile ~~ s| $( Q[.] ) .* ||;
>>
>> ($TmpFile, $TmpHandle) = tempfile(:tempdir("."), $TmpFile ~ "_******"
>> ~ ".tmp" );
>> ...
>> ($TmpFile, $TmpHandle) = tempfile(:tempdir("."), :!unlink);
>>
>
>
> It seems that all my tmp files are being removed
> when my program exits normally. It was crashing
> until I fix a problem.
>
> But why wait till the program exits when I tell
> it to unlink before that?