Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #40816] open opcode creates file if it doesn't exist

8 views
Skip to first unread message

Jonathan Rockway

unread,
Nov 11, 2006, 2:53:28 PM11/11/06
to bugs-bi...@rt.perl.org
# New Ticket Created by Jonathan Rockway
# Please include the string: [perl #40816]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=40816 >


Not sure if this is a bug or not, but I noticed that the open opcode
creates its argument if the desired file doesn't exist. Here's a test
case:

.sub main :main
.param pmc args
.local pmc file
$S0 = shift args # script name
$S0 = shift args # first argument
file = open $S0
end
.end

Run as "parrot test.pir <filename>". If filename doesn't exist, it
will be created.

BTW, this is my first PIR script, so please be gentle :)

Regards,
Jonathan Rockway

jnthn@jnthn.net via RT

unread,
Dec 16, 2006, 1:55:16 PM12/16/06
to perl6-i...@perl.org
On Sat Nov 11 11:53:27 2006, j...@jrock.us wrote:
> Not sure if this is a bug or not, but I noticed that the open opcode
> creates its argument if the desired file doesn't exist.
>
There are two variants of the open opcode: this one, and one where you
can specify a mode. The default open mode at the moment is "+<" - that
is, open for read and create it if it doesn't exist. You can specify
another operand to open specifying the open mode "<" instead, which will
just open the file and not create it.

So, I think this is not a bug - yes, we could argue all day about what
the default open mode should be, but there's a perfectly good way to be
explicit about you want that's only a few characters to type. :-)

Jonathan

Jerry Gay

unread,
Dec 18, 2006, 12:00:15 PM12/18/06
to parrotbug...@parrotcode.org, perl6-i...@perl.org
pardon my ignorance, because i haven't checked the documentation, but
is the behavior in the last paragraph documented? arguably, it is a
bug in the C<open> documentation unless that opcode it is described as
defaulting to '+<'.
~jerry
0 new messages