in reply to Using IO::File to redirect STDOUT

As you can see from the error message, STDOUT is a IO::Handle (which doesn't have an open method), not a IO::File (which does). Use open(*STDOUT, '>', $logfile).

Replies are listed 'Best First'.
Re^2: Using IO::File to redirect STDOUT
by njcodewarrior (Pilgrim) on May 08, 2006 at 11:22 UTC

    Quoting from the book "Network Programming with Perl" by Lincoln D. Stein (pp 29 - 30):

    'When you load IO::File (technically, when IO::File loads IO::Handle, which it inherits from), it adds methods to ordinary filehandles. This means that any of the methods in IO::File can also be used with STDIN, STDOUT, STDERR or even with any of the conventional filehandles that you happen to create'.

    Is the book incorrect or am I missing something?

    njcodewarrior

      That's wrong.
      "This means that any of the methods in IO::File"
      should read
      "This means that any of the methods in IO::Handle"

      The following are methods IO::File has, but IO::Handle does not:

      • open
      • binmode
      • seek
      • sysseek
      • tell

        Okay, bear with me as I'm more confused than ever. Here's another piece directly from the text (pp 30 - 31):

        "...$result = $fh->open($filename,[,$mode [,$perms]]) You can reopen a filehandle object on the indicated file by using its open() method. The input arguments are identical to new(). The method result indicates wheter the open was successful.
        This is chiefly used for reopening the standard filehandles STDOUT, STDIN, and STDERR. For example:
        STDOUT->open(">log.txt") or die "Can't reopen STDOUT: $!";
        Calls to print() will now write to the file log.txt...."

        This is also incorrect?

        Thanks again for the help,
        njcodewarrior

        Although of course in the case of seek/tell/sysseek it is because IO::Handle is _also_ not an IO::Seekable object.

        @IO::File::ISA = qw{ IO::Handle IO::Seekable };