Close($file) required in Perl 6, unlike Perl 5

Peter Lobsinger plobsing at gmail.com
Mon Jul 18 14:41:30 UTC 2011


On Sun, Jul 17, 2011 at 11:00 AM, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Sun, Jul 17, 2011 at 10:21:19AM +0200, Moritz Lenz wrote:
>>
>> Question to the Parrot developers: How could I implement DESTROY methods
>> in Rakudo? Is there any vtable I can override, or so? Note that such a
>> method might itself allocate new GCables. While not urgent, it's
>> important for us in the long run.
>
> A possibly related (and more relevant) question for Parrot devs:
> is there any reason that FileHandle PMCs do not automatically
> flush + close on destruction?

The destructor does exactly that, but is not triggered by global teardown.

>    pmichaud at kiwi:~/nom$ cat fh.pir
>    .sub 'main' :main
>        $P0 = new ['FileHandle']
>        $P1 = $P0.'open'('test.txt', 'w')
>        $P1.'print'("Hello\n")
>    .end
>
>    pmichaud at kiwi:~/nom$ install/bin/parrot fh.pir
>    pmichaud at kiwi:~/nom$ cat test.txt
>    pmichaud at kiwi:~/nom$ ls -l test.txt
>    -rw-r--r-- 1 pmichaud pmichaud 0 2011-07-17 09:57 test.txt

.sub 'main' :main
 $P0 = new ['FileHandle']
 $P0.'open'('test.txt', 'w')
 $P0.'print'("Hello\n")
 $P0 = null
 sweep 1
.end

> Pm
> _______________________________________________
> http://lists.parrot.org/mailman/listinfo/parrot-dev
>


More information about the parrot-dev mailing list