On Mon, Jun 18, 2001 at 12:52:40PM -0700, Paul Burkett wrote:
> What is the difference between sysopen and open?

The arguments, plain and simple.

The handle created by sysopen is the same as that created by an equivalent
open call, the only difference is in what arguments the functions take, and
how they handle their arguments.

The biggest difference is in open's typical form:

    open(FILEHANDLE, $filename)

$filename is treated magically, in that leading and trailing characters
determine how the file is opened.  The typical read-only and write-only
modes are the "<" and ">" prefixes, respectively.  As a good example of
open's magic if $filename starts with "|" the string after that is
evaluated as a program, which is subsequently executed, and anything printed
to the filehandle goes to the standard input of the program.  Further gory
details should be gleaned from perldoc -f open and perldoc perlopentut.


sysopen allows finer-grained control.  The form I usually use is:

    sysopen(FILEHANDLE, $filename, $mode)

If you've ever used C, this is much like open().  $mode is lifted directly
from C, or'd flags and all.  I typically use it when I want to make sure the
file I'm opening doesn't exist beforehand (typically used prior to locking).

    sysopen(FILEHANDLE, $filename, O_WRONLY|O_CREAT|O_EXCL);

This opens the file in write-only mode, creating it if it doesn't exist, and
refusing to open the file (and returning an error) if it does exist.  See
perldoc -f sysopen.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to