Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

Comment on open vs sysopen
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 (Bishop) 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 ikegami (Pope) on May 31, 2010 at 03:47 UTC
    The syntax.
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 $!;

    HTH,
    Thomas

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://842177]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-08-29 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls