Grupos de Google ya no admite publicaciones ni suscripciones nuevas de Usenet. El contenido anterior sigue visible.

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

8 vistas
Ir al primer mensaje no leído

Jonathan Rockway

no leída,
11 nov 2006, 2:53:28 p.m.11/11/06
para 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

no leída,
16 dic 2006, 1:55:16 p.m.16/12/06
para 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

no leída,
18 dic 2006, 12:00:15 p.m.18/12/06
para 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 mensajes nuevos