J
Jim Cochrane
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!
--
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!
--