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?
Asked
Active
Viewed 208 times
6

Community
- 1
- 1

brian d foy
- 129,424
- 31
- 207
- 592
1 Answers
8
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).

Christoph
- 164,997
- 36
- 182
- 240