in reply to Can I include O_CREAT, O_EXCEL and O_WRONLY in my script without always requiring Fcntl?

add an empty pair of parens after the constant names when using them: O_CREAT().
  • Comment on Re: Can I include O_CREAT, O_EXCEL and O_WRONLY in my script without always requiring Fcntl?
  • Download Code

Replies are listed 'Best First'.
Re^2: Can I include O_CREAT, O_EXCEL and O_WRONLY in my script without always requiring Fcntl?
by rzward (Monk) on Apr 13, 2006 at 18:00 UTC
    Thank you! That appears to work. My test program would then look like this:
    use strict; print &openit; sub openit { eval "use Fcntl qw(O_CREAT O_EXCL O_WRONLY);"; die $@ if ($@); my $fp = "c:\\temp\\test.csv.lck.tmp"; die "Unable to open $fp" if !sysopen (my $fh, $fp, O_WRONLY() | O_CR +EAT() | O_EXCL()); close $fh; unlink $fp; return $fp; }

    Thanks again.

    Richard

      you can also eliminate the eval/use statement replacing it by a require one and then call the constant subs prefixed with the package name:
      sub openit { require Fcntl; my $fp = "c:\\temp\\test.csv.lck.tmp"; die "Unable to open $fp" if !sysopen (my $fh, $fp, Fcntl::O_WRONLY() + | Fcntl::O_CREAT() | Fcntl::O_EXCL()); close $fh; unlink $fp; return $fp; }