I couldn't get this out of my head so I looked at the Perl C code. While it was hard to follow until I scanned the .h's for pre-defs.. I think I have the jist of it: (Please note this is 5.8.7)


From perlio.c:
PerlIO * PerlIO_openn(pTHX_ const char *layers, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args) { if (narg) { if (narg > 1) { Perl_croak(aTHX_ "More than one argument to open"); } if (*args == &PL_sv_undef) return PerlIO_tmpfile(); else { char *name = SvPV_nolen(*args); if (*mode == IoTYPE_NUMERIC) { fd = PerlLIO_open3(name, imode, perm); if (fd >= 0) return PerlIO_fdopen(fd, (char *) mode + 1); } else if (old) { return PerlIO_reopen(name, mode, old); } else { return PerlIO_open(name, mode); } } } else { return PerlIO_fdopen(fd, (char *) mode); } return NULL; }
PerlIO_openn is called from do_openn, with narg being the number of scalar arguments (3rd arg for Perl open) and args being the scalar values. You'll see that no matter what, if the args are undef, it returns the PerlIO_tmpfile. There is no check for mode here, because that was done in the previous function, do_openn (which is defined as Perl_do_openn)

From doio.c:(PerlIO_do_openn)
... if ((*type == IoTYPE_RDWR) && /* scary */ (*(type+1) == IoTYPE_RDONLY || *(type+1) == IoTYPE_WRONLY) && ((!num_svs || (tend > type+1 && tend[-1] != IoTYPE_PIPE)))) { TAINT_PROPER("open"); mode[1] = *type++; writing = 1; }
Here is the check for the leading '+' (IoTYPE_RDWR). It is the ONLY check in this function and just sets the writing flag and moves the pointer on the "type" up by one.
We'll move on to where it goes when it's readonly (remember, it's already processed any '+' so it still goes here regardless)
else if (*type == IoTYPE_RDONLY) { /*SUPPRESS 530*/ for (type++; isSPACE(*type); type++) ; mode[0] = 'r'; #ifdef HAS_STRLCAT if (in_raw) strlcat(mode, "b", PERL_MODE_MAX); else if (in_crlf) strlcat(mode, "t", PERL_MODE_MAX); #else if (in_raw) strcat(mode, "b"); else if (in_crlf) strcat(mode, "t"); #endif if (*type == '&') { goto duplicity; } if (*type == IoTYPE_STD && (!type[1] || isSPACE(type[1]) | +| type[1] == ':')) {
so far so good.. unless we're doing a <& or <- we can skip this if logic.
... else { if (!num_svs) { namesv = sv_2mortal(newSVpvn(type,strlen(type))); num_svs = 1; svp = &namesv; type = Nullch; } fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs, +svp); }
Well, as we can see, regardless of the original num_svs, there is going to be a value of at least 1 passed to the above PerlIO_openn. Even if svp is undef, it goes and opens a temp file.

if (!fp && type && *type && *type != ':' && !isIDFIRST(*ty +pe)) goto unknown_open_mode; }
Since we have a valid fp (PerlIO_tmpfile), we're in the clear.

Note that there is more to this function that the snippets I've provided, but it seems that it would be the same whether or not there was a '+' before the '<' or '>'

This is my first time delving into the perl C-source. If I've said anything that's blatantly wrong, I apologize, and please do correct me in the thread. I just wanted to research this and share my psuedo-findings with the rest of the monastery.

In reply to Re: 3-arg open() does not give warnings!? by Transient
in thread 3-arg open() does not give warnings!? by graff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.