in reply to TIMTOWTDI Challenge: Open a file

The sysopen call is sometimes useful for its full range of open modes, and the ability to set file permissions when the file is created.

sysopen FILEHANDLE,FILENAME,MODE,PERMS

If you fool around with that, use Fcntl;. That lets you take your program to another machine without worrying about differing numeric values for the system constants.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: TIMTOWTDI Challenge: Open a file
by McDarren (Abbot) on Apr 18, 2006 at 01:05 UTC
    I use sysopen when I want my scripts to play nicely with each other, and observe locking. eg:
    use Fcntl qw(:DEFAULT :flock); sysopen(OUT, $file, O_WRONLY | O_CREAT) or die "Cannot open $file for writing:$!\n"; flock(OUT, LOCK_EX) or die "Cannot get a lock on $file:$!\n";

    (That example is pretty much straight out of the book)

    Cheers,
    Darren :)