Reputation: 25133
I am using code from here:
#!/usr/bin/perl
use strict;
use warnings;
use Fcntl;
my $flags = "";
fcntl( STDIN, F_GETFL, $flags) || die $!;
$flags |= O_NONBLOCK;
fcntl( STDIN, F_SETFL, $flags) || die $!;
But get next error:
Argument "\0O§"U\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0..." isn't numeric in bitwise or (|) at /home/user/inetd-script.pl line 9.
$flags
is initialized by fcntl
call. Tell me please why this error occur.
And how to fix it.
UPD
Perl cookbook 7.20.2 initialized it as empty string.
Upvotes: 0
Views: 698
Reputation: 98388
The bitwise operators have two flavors, string and numeric. If either operand is numeric, or the "bitwise" feature[^1] is enabled, it is treated as a numeric bitwise. In that case, if an other operand is a string, it is converted to a number, and a warning is generated if it doesn't look like a number.
You should be initializing $flags to 0, not ""
.
[^1]: the "bitwise" feature makes the normal bitwise operators only do numeric bitwise, and adds new string bitwise operators such as |.
.
Upvotes: 6