in reply to more than 3 arguments to open?

update:

Sorry I didn't understand your question carefully at first.

Any way, let me complete my reply with four-argument open (To be precise, four or more arguments, as Perl will flatten that LIST for us, but we are okay, as that's the last argument.):

open FILEHANDLE,MODE,EXPR,LIST

When LIST is specified, it contains a list of arguments that would be passed into "a command". Make it plain, this is only meaningful, when you open a pipe, and the list of argument will be passed to the child process.

The usage of LIST might be extended in the future, but (again) currently this syntax is only meaningful when used with pipe.

However, the bad news is that this feature is documented, but not implemented in 5.8. When you try to test, it tells you that open with list syntax is not implemented.

Don't mix this up with what blokhead talked about, in Perl 5.8, it is perfectly right to use |, -|, |- etc as MODE argument.

Original reply

(I misunderstood John's post at the beginning, and thought he wanted to know about the mode ;), any way, I just leave it here, as it might be useful to other monks)

Two examples:
  1. Open for reading:
    open(AFILE, "<", "afile.txt");
    This is the same as saying:
    open(AFILE, "<afile.txt");
  2. Open with utf8 layer (if your file contains unicode):
    open(AFILE, "<:utf8", "afile.txt");

Replies are listed 'Best First'.
Re: Re: more than 3 arguments to open?
by blokhead (Monsignor) on Jan 07, 2003 at 07:15 UTC
    In response to your updated reply:

    I noticed the same explanation in my docs, but that's for Perl 5.8. There is nothing mentioned in the 5.6 docs, as John noticed. I can't get the same behavior from 5.6:

    open(F, '', '/bin/ls', '-l') || die $!; open(F, '-|', '/bin/ls', '-l') || die $!; # works in 5.8 open(F, '|', '/bin/ls', '-l') || die $!; open(F, '|', '|/bin/ls', '-l') || die $!;
    All of these die with "Can't use an undefined value as filehandle reference at ..." under 5.6.

    If you're sure this behavior is the same in 5.6 and 5.8, just undocumented in 5.6, can you show examples of the correct modes to use?

    blokhead

      Checked your other posts from the last couple of days, Hm...your tone is alwasy so feverish. Are you a monk? or a combatant?

      This is not the first time, you see features SPECIFIED in document, but not implemented. One simple example: alarm is not implemented on win32, even in perl 5.8, but alarm is still documented, and it is never stated anywhere in doc that alarm actually does not work on win32.

      This does not mean that people can not discuss, and make themselves ready for the future.

      I pray for PEACE.
        [...] it is never stated anywhere in doc that alarm actually does not work on win32.
        it is even worse. have a look into the windows quirks section. there is a list which contains all not-implemented functions on the win platform - the alarm () function is mentioned here.

        the point is that alarm () does work (AS 5.8 804) in spite of being not implemented ... ;) on the other hand, why should unix specifics be implemented on an other platform?
        Hmm, maybe it's cabin fever. But you are right, a few of my recent nodes might give a bad impression. Anyway, I haven't been consciously trying to nitpick or be confrontational. Maybe we can call it over-enthusiasm.

        Taking a break from the computer... ;)

        blokhead

Re: Re: more than 3 arguments to open?
by John M. Dlugosz (Monsignor) on Jan 07, 2003 at 06:36 UTC
    Your examples only have 2 or 3 arguments. I know what those mean. What if you say
    open (AFILE, $modes, "foo", "bar", "baz")
    That is, more than three arguments?