According to the open docs, there are adverbs for reading, writing, and appending. That's fine and what I would expect. I have a particular application that uses sysopen
for better control and I was trying to rewrite it in Perl 6. I know about NativeCall
(as mentioned in my question about kill
), but is there something builtin that I'm missing?
This is a case of incomplete documentation:
On MoarVM, open
has supported the more common ones of the POSIX flags since 2015, including O_EXCL
via the named parameter :exclusive
.
The flag combination you're looking for is
my $fh = open "file", :mode<wo>, :create, :exclusive;
which can be written more compactly as
my $fh = open "file", :x;
This will hopefully be documented as part of the ongoing grant Standardization, Test Coverage, and Documentation of Perl 6 I/O Routines. For now, details can be found in the commit log. There have been some minor changes since then; in particular, :mode<pipe>
has been removed and a JVM implemetation added (which however does not allow you to combine flags as freely as MoarVM does).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With