John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

The perlfunc says
open FILEHANDLE,MODE,LIST
in the Perl 5.6.1 documentation.

What is the meaning of additional arguments beyond the filename as the 3rd?

Replies are listed 'Best First'.
Re: more than 3 arguments to open?
by pg (Canon) on Jan 07, 2003 at 06:23 UTC
    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");
      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.
      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?

Re: more than 3 arguments to open?
by Juerd (Abbot) on Jan 07, 2003 at 10:40 UTC

    What is the meaning of additional arguments beyond the filename as the 3rd?

    Nothing with Perl 5.6 (I recall it gives some strange errors about undefined values), but with 5.8, you can specify a list of command line arguments to avoid using the shell as you can with system.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      I see. They planned for this when the added the syntax to separate out the MODE, but didn't get back to it until later.