I got the following code to try out file opening and writing (without spurt):
sub MAIN {
my $h = open 'somefile.txt', :w, :a;
for 1..4 {
$fh.put: "hello";
}
$fh.close;
}
What I expected is that with each run, it should append 4 additional lines with "hello" to the file. However it still seems to overwrite the file, after 2 or more runs there are still only 4 lines.
$ perl6 opening.p6
$ cat somefile.txt
hello
hello
hello
hello
$ perl6 opening.p6
$ cat somefile.txt
hello
hello
hello
hello
Adding or removing :a
or :append
doesn't seem to influence this behaviour, what am I missing?
:r
,:w
,:a
,:x
,:update
,:rw
,:ra
, or:rx
in any givenopen
call. You should not combine them. You should not use the other modes.