Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

open vs sysopen

by littlemonk (Sexton)
on May 29, 2010 at 14:09 UTC ( #842177=perlquestion: print w/replies, xml ) Need Help??
littlemonk has asked for the wisdom of the Perl Monks concerning the following question:

Hi to all ...anybody plz tell me the difference between open(),sysopen()......!thanks in advance

Replies are listed 'Best First'.
Re: open vs sysopen
by Corion (Pope) on May 29, 2010 at 14:11 UTC

    Just read the documentation for open and for sysopen. As they are different, the difference in content will likely be the difference in operation.

Re: open vs sysopen
by ww (Archbishop) on May 29, 2010 at 14:15 UTC

    You'll learn not only the answer but also an approach to similar questions from this:

    perldoc -f open perldoc -f sysopen
Re: open vs sysopen
by rowdog (Curate) on May 30, 2010 at 13:02 UTC

    perlopentut says

    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.
Re: open vs sysopen
by tomfahle (Priest) on Jun 02, 2010 at 13:02 UTC

    As stated before sysopen comes with more precision than open.

    sysopen helps avoiding race-conditions.

    Consider the following snippet:

    if (-e $file) { open(FH,">","$file") or die $!; }

    It's a two step process:

    1. File test
    2. open

    sysopen needs only one step (kind a simplistic, but you should get the message).

    use Fcntl; sysopen(FH, $file, O_WRONLY|O_TRUNC|O_CREAT, 0600) or die $!;


Re: open vs sysopen
by ikegami (Pope) on May 31, 2010 at 03:47 UTC
    The syntax.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://842177]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-11-25 00:30 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (354 votes). Check out past polls.