[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] IO::Handle



At 11:15 AM +0000 on 12/28/96, Nigel Chapman wrote:


}I am puzzled.  In the synopsis for IO::Handle it gives the following example:
}
}    use IO::Handle;
}
}    $fh = new IO::Handle;
}    if ($fh->open "< file") {
}        print <$fh>;
}        $fh->close;
}    }
}
}Even if you correct the syntax error, it doesn't work.  There is no open
}method defined for this class, and the autoloader cannot find one.  (I am
}using MacPerl5.10r2, standalone 68k version, both Big and ordinary, and the
}latest version 1.14 of IO::Handle.)  Is it supposed to autoload something,
}which is not present in my set-up (does autoloading only work on
}PowerMacs?), or is the documentation just out of date (there was an open
}method which worked fine with the old FileHandle class)?

You're right in that there seems to be no open method in File::Handle.  Your
example script fails to work on a Sun workstation running Perl 5.003 and
the latest version of the IO package, 1.14.  It fails trying to autoload
open.  This seems to be a documentation problem, since the IO::File class
seems to be just the IO::Handle class with an open method.  Using IO::File
instead of IO::Handle is the first step in fixing this.

However, there's a second, very minor, problem I noticed if you use
IO::File, and :lib:IO:File.pm will therefore go into my small collection of
fixed library routines.  On lines 138-142 an attempt is made to protect
leading whitespace in a name by putting the appropriate thing at the front
of the name (":" for Macs and "./" for Unix).  However, the Mac version
puts a ":" on the name all the time unless it begins with /.  So the fix to
line 139 in File is simply:

            $file = ":" . $file unless $file =~ m#^\S#;

}You can work round it by just calling open as an ordinary function:
}    $fh = new IO::Handle;
}    if (open ($fh, "< file")) {
}      print <$fh>;
}      $fh->close;
}    }
}but this seems very strange to me...why should close and everything else be
}a method if open is not?
}
}I would be grateful if anyone could enlighten me as to whether this is a
}MacPerl problem, a feature of the module, or some misconception of mine.

Mostly it seems to be a mistake in the documentation of the module, which
has not been fixed in IO-1.14.

}
}Thanks.


--------
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693
Greenbelt, MD 20770
schinder@pjstoaster.pg.md.us