Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
- From: Jim Cochrane <allergic-to-spam@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Sep 2007 09:01:28 +0200 (CEST)
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 |=.
--
.
- References:
- Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
- From: Jim Cochrane
- Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
- From: Ben Morrow
- Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
- Prev by Date: Re: in what array do all the $1,$2,... live?
- Next by Date: FAQ 3.21 How can I compile my Perl program into byte code or C?
- Previous by thread: Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
- Next by thread: Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
- Index(es):
Relevant Pages
|
|