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




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";
$flags |= O_NONBLOCK;
fcntl(HANDLE, F_SETFL, $flags) or die "Couldn't set flags: $!\n";

(I've typed the above by hand and shortened the error messages - sorry
for any typos.)

I did some searching, including messages about similar problems in this
NG, but failed to find anything relevant.

My code, a short example (included below), produces the warning:

Argument "\0\0\0\0/test1\0\0^P\0\0\0XM-3j^ITLKW \0\0\0^P\0\0\0hM-3..." isn't numeric in bitwise or (|) at ./odd-flags.pl line 13.

This refers to the line:

$flags |= O_NONBLOCK;

I suspect this has something to do with this paragraph from the fcntl
man page:

You donâ??t have to check for "defined" on the return from
"fcntl". Like "ioctl", it maps a 0 return from the system call
into "0 but true" in Perl. This string is true in boolean con-
text and 0 in numeric context. It is also exempt from the nor-
mal -w warnings on improper numeric conversions.

But the last sentence appears to imply the above warning should not
occur.

FYI:
perl -v

This is perl, v5.8.6 built for i386-linux-thread-multi

Is the perl version I'm using mistakenly producing this warning or have
I missed something? If the former - any recommendations on how to
cleanly suppress the warning. (Turn warnings off just for the
"offending" line?)

Here's my example code:

------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

use Fcntl;

my $file;
open $file, '>/tmp/test1';
my $flags = '';
fcntl($file, F_GETFL, $flags) or die "Could not get flags: $!";
print "flags: $flags\n";
$flags |= O_NONBLOCK;
print "flags: $flags\n";
fcntl($file, F_SETFL, $flags) or die "Could not set flags: $!";

fcntl($file, F_GETFL, $flags) or die "Could not get flags: $!";
print "flags: $flags\n";

# Below lines added only to get more info about the problem:
fcntl($file, F_GETFL, $flags) or die "Could not get flags: $!";
print "flags: $flags\n";
$flags |= 8;
print "flags: $flags\n";
fcntl($file, F_SETFL, $flags) or die "Could not set flags: $!";

fcntl($file, F_GETFL, $flags) or die "Could not get flags: $!";
print "flags: $flags\n";

------------------------------------------------------------------

Oddly, it complains about the first |=, but not the 2nd. It produces
this output (sorry about the odd characters):


Argument "\0\0\0\0/test1\0\0^P\0\0\0XM-cp^ITLKW \0\0\0^P\0\0\0hM-c..." isn't numeric in bitwise or (|) at ./odd-flags.pl line 13.
flags: flags: 2048
flags: 2048flags: 2048flags: 2056
flags: 2056


Thanks for any help or pointers on this!

--

.



Relevant Pages

  • 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)
  • Re: Using fcntl and |= - "Argument .... isnt numeric in bitwise or ..."
    ... I'm stumped - trying to get rid of a warning message with code based on ... F_GETFL Get descriptor status flags, ... So, contrary to the example in perldoc -f fcntl, you need ...
    (comp.lang.perl.misc)
  • Re: ANNOUNCE: DBD:Oracle 1.18
    ... Well a warning in one compiler is better than and error in an other so I ... This might be a problem more with the older oracle OCI in your client. ... perl -Mblib t/26exe_array.t ...
    (perl.dbi.users)
  • AW: Problems building DBD-Oracle-1.16 on HP
    ... Looks as if gcc gets some parameters it does not understand. ... I have tried all the various incantations listed in the READMEs (perl ... Oracle version 10.2.0.2 ... Oracle.c:24: warning: 'RETVAL' might be used uninitialized in this ...
    (perl.dbi.users)
  • Help: Install DBI-Oracle on cygwin with Perl 5.8.0
    ... I am new in the Perl world. ... Xlib.xs:383: warning: cast to pointer from integer of different size ...
    (comp.lang.perl.modules)