title: File locking with Fcntl: Baffling bug involving 'use' and 'require'
body: <p>The following Perl script outputs "SUCCESS" as you'd expect:</p>
  
  <pre><code>use Fcntl qw(:DEFAULT :flock);
  sysopen(LF, "test.txt", O_RDONLY | O_CREAT) or die "SYSOPEN FAIL: $!";
  if(flock(LF, LOCK_EX)) { print "SUCCESS.\n"; }
  else { print "FAIL: $!\n"; }
  </code></pre>
  
  <p>But now, replace that first line with</p>
  
  <pre><code>require "testlib.pl";
  </code></pre>
  
  <p>where testlib.pl contains</p>
  
  <pre><code>use Fcntl qw(:DEFAULT :flock);
  
  1;
  </code></pre>
  
  <p>Now, strangely enough, the script fails, like so:</p>
  
  <pre><code>FAIL: Bad file descriptor
  </code></pre>
  
  <p>The question: Why?</p>
  
  <p>ADDED:</p>
  
  <p>And now that I know why -- thanks! -- I'm wondering what is the best way to deal with this:</p>
  
  <ol>
  <li>Just do the <code>use Fcntl</code> twice, once in the main script and once in the required library (both the main script and the library need it).</li>
  <li>Replace O_RDONLY with &amp;O_RDONLY, etc.</li>
  <li>Replace O_RDONLY with O_RDONLY(), etc.</li>
  <li>Something else?</li>
  </ol>