develooper Front page | perl.perl5.porters | Postings from October 2018

Re: [perl #133505] open() dies for invalid modes, instead ofreturning undef, as documented

Thread Previous | Thread Next
Sawyer X
October 5, 2018 19:42
Re: [perl #133505] open() dies for invalid modes, instead ofreturning undef, as documented
Message ID:

On 09/08/2018 05:58 PM, R. Diez via perl5-porters wrote:
>> [...]
>> Given that, it shouldn't be surprising that you get what
>> is indeed a run-time error when you use open with an invalid mode.
> I think you misinterpreted my report. Getting a run-time error is fine. The trouble is, the documentation states that run-time errors in open() are signalled by returning "undef", but in this particular case, open() dies itself, instead of returning undef. So my own "die" statement afterwards does not run at all. Try my example and you will see what I mean.

The documentation mentioning a run-time return value for open() is
describing the result of trying to open a file. This happens after
open() has a legal mode for opening it. If it does not have a legal mode
for opening a file, it will crash, because it cannot attempt that. There
are other cases in which open() would set $! (EPIPE), but there are also
additional cases in which it will croak without returning a value and
setting $! (too many arguments to open).

Think of it as when open() tries to (or is about to try to) open
something and does system checks and when open() is simply making sure
you called it correctly.

I don't see what should be changed here.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About