It seems both do the same thing, huh?
Can someone show me an example where they do different job?
It seems both do the same thing, huh?
Can someone show me an example where they do different job?
sysopen
is a thin wrapper around the open(2)
kernel system call (the arguments correspond directly), whereas open
is a higher-level wrapper which enables you to do redirections, piping, etc.
Unless you are working with a specific device that requires some special flags to be passed at open(2)
time, for ordinary files on disk you should be fine with open
.
open(2)
is, all of which is OS stuff, not Perl-specific.
Sep 20, 2011 at 15:02
O_WRONLY|O_EXCL|O_CREAT
combo, i.e. "create and write if not exists". Using -f ... or open ...
instead is just asking for race condition.
Sep 20, 2011 at 15:28
To quote perlopentut:
If you want the convenience of the shell, then Perl's open is definitely the way to go. On the other hand, if you want finer precision than C's simplistic fopen(3S) provides you should look to Perl's sysopen, which is a direct hook into the open(2) system call. That does mean it's a bit more involved, but that's the price of precision.
Since Perl is written in C, both methods likely end up making the open(2)
system call. The difference is that open()
in Perl has some niceties built in that make opening, piping and redirection very easy. At the same time, though, open()
takes away some flexibility. It has none of the Fcntl
functionality available in sysopen()
, nor does it have the masking functionality.
Most situations just need open()
.
Fcntl
and masking functionality available in sysopen
?
Fcntl
features. That section begins with the phrase "And here are things you can do with sysopen that you cannot do with a regular open." Enjoy!
Sep 21, 2011 at 14:16