Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."



On 2007-09-29, Ben Morrow <ben@xxxxxxxxxxxx> wrote:

Quoth Jim Cochrane <allergic-to-spam@xxxxxxxxxxxxxxxxxxx>:

I'm stumped - trying to get rid of a warning message with code based on
this example snippet from the "Perl Cookbook" book:

use Fcntl;

$lags = "";
fcntl(HANDLE, F_GETFL, $flags) or die "Couldn't get flags: $!\n";

You need to read you systems fcntl(2) as well as the perldocs; at least
on mine, it says

F_GETFL Get descriptor status flags, as described below (arg is
ignored).

So, contrary to the example in perldoc -f fcntl, you need

my $flags = fcntl(HANDLE, F_GETFL);


This appears to be wrong. It looks like fcntl takes 3 arguments with
F_GETFL, even though the 3rd arg is not passed as a reference. (Trying
it with just 2 args -

$flags = fcntl($handle, F_GETFL) or die "Could not get flags: $!";

produces the error:

Not enough arguments for fcntl at ./exp8.pl line 37, near "F_GETFL) "
)

However, it looks like the answer to my question is that the warning
occurs because the example is based on old code that does not 'use
warnings' and thus does not produce a warning message unless 'use
warnings' is added. I found that instead of doing this, which produced
the warning:

fcntl($file, F_GETFL, $flags) or die "Could not get flags: $!";
$flags |= O_NONBLOCK;
fcntl($file, F_SETFL, $flags) or die "Could not set flags: $!";

doing it this way does not produce a warning:

fcntl($file, F_GETFL, $flags) or die "Could not get flags: $!";
fcntl($file, F_SETFL, $flags | O_NONBLOCK) or die "Could not set flags: $!";

So to answer my own question, the warning is expected and the best way
to get rid of it is to simply use the latter form instead of changing
the value of $flags with |=.


--

.



Relevant Pages

  • Using fcntl and |= - "Argument .... isnt numeric in bitwise or ..."
    ... I'm stumped - trying to get rid of a warning message with code based on ... $flags |= O_NONBLOCK; ... I suspect this has something to do with this paragraph from the fcntl ... into "0 but true" in Perl. ...
    (comp.lang.perl.misc)
  • Re: Using fcntl and |= - "Argument .... isnt numeric in bitwise or ..."
    ... You've excerpted my typed-in quote from the Perl Cookbook, ... You aren't even checking the return result from fcntl. ... What I found was that the warning message occurs because the 'use ... non-numeric value assigned to the $flags variable by the first fcntl ...
    (comp.lang.perl.misc)
  • tie problem
    ... I am writing a script which accesses a DBM file using SDBM. ... program works but throws out a warning of: ... I've included Fcntl but that doesn't solve the problem. ...
    (comp.lang.perl.misc)
  • SDBM_File Error: Argument "O_RDWR" isnt numeric in null operation
    ... I am writing a script which accesses a DBM file using SDBM. ... program works but throws out a warning of: ... I've included Fcntl but that doesn't solve the problem. ...
    (comp.lang.perl)
  • Re: help needed please!
    ... But some compilers like to give you a warning ... Each warning a compiler can give you is important when you not ... but you may use flages to handle flags to handle flags when you ... >> stdout is line bufferd and until one or both of the following cases is ...
    (comp.lang.c)