Re: flushing a file

2010-09-15 Thread Patrick R. Michaud
On Wed, Sep 15, 2010 at 08:42:48AM +0200, Gabor Szabo wrote:
> Can I rely in Perl 6 that a file is flushed and closed correctly when
> Perl shuts down?

I don't know the answer to this question, but I suspect "yes".

> The probably more interesting case is this:
> 
> #!/usr/bin/perl6
> use v6;
> 
> my $filename = "temp.txt";
> 
> {
> my $fh = open $filename, :w;
> $fh.say("hello world");
> }
> ...
> Can I be sure that the file is already flushed and closed when $fh
> goes out of scope
> or do I need to explicitly call $fh.close in the first block?

You need to explicitly call $fh.close.

Pm


flushing a file

2010-09-14 Thread Gabor Szabo
I updated my Perl 6 slides and Masak commented on a lot of my slides. Thank You!

For example for writing to a file I had the following:

#!/usr/bin/perl6
use v6;

my $filename = "temp.txt";

my $fh = open $filename, :w;
$fh.say("hello world");


Masak: > I'd recommend $fh.close; it's more important than in Perl 5
because of the new GC.


Which brings up a question:
Can I rely in Perl 6 that a file is flushed and closed correctly when
Perl shuts down?


The probably more interesting case is this:

#!/usr/bin/perl6
use v6;

my $filename = "temp.txt";

{
my $fh = open $filename, :w;
$fh.say("hello world");
}

{
   my $in = open $filename;
   say $in.lines
}


Can I be sure that the file is already flushed and closed when $fh
goes out of scope
or do I need to explicitly call $fh.close in the first block?

Gabor