in reply to Re: Using IO::File to redirect STDOUT
in thread Using IO::File to redirect STDOUT

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

  • Comment on Re^2: Using IO::File to redirect STDOUT

Replies are listed 'Best First'.
Re^3: Using IO::File to redirect STDOUT
by ikegami (Patriarch) on May 08, 2006 at 13:24 UTC

    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

        That's the code you had in your OP. As you know, that doesn't work.
      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 };