[29649] in Perl-Users-Digest
Perl-Users Digest, Issue: 893 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 1 11:10:15 2007
Date: Mon, 1 Oct 2007 08:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 1 Oct 2007 Volume: 11 Number: 893
Today's topics:
constraints in perl <sting.t2@gmail.com>
Re: constraints in perl <wahab@chemie.uni-halle.de>
Re: constraints in perl <scobloke2@infotop.co.uk>
Re: constraints in perl <sting.t2@gmail.com>
Re: constraints in perl <wahab@chemie.uni-halle.de>
Re: in what array do all the $1,$2,... live? <nobull67@gmail.com>
Re: looping questions <lerameur@yahoo.com>
Odd regex behavior <tony@skelding.co.uk>
Re: Odd regex behavior <benkasminbullock@gmail.com>
Re: Odd regex behavior <mritty@gmail.com>
Re: Odd regex behavior <mritty@gmail.com>
Re: Odd regex behavior (Greg Bacon)
Re: Problem installing IO::Compress::Base <paul.marquess@btinternet.com>
Re: Small doubt in perl <anilkumar.iitm@gmail.com>
Re: Small doubt in perl <bik.mido@tiscalinet.it>
Re: Small doubt in perl <anilkumar.iitm@gmail.com>
Re: Using fcntl and |= - "Argument .... isn't numeric i <allergic-to-spam@no-spam-allowed.org>
Re: Using fcntl and |= - "Argument .... isn't numeric i <No_4@dsl.pipex.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 01 Oct 2007 14:10:50 -0000
From: Amir <sting.t2@gmail.com>
Subject: constraints in perl
Message-Id: <1191247850.042998.273520@n39g2000hsh.googlegroups.com>
hi,
I have a small question
if I have a variable called $foo , and I want to check that this
variable "bits" 20-23 and 31 is equal to other variable $too "bits"
12-14 and 29,respectively.
I mean $foo[20]=$too[12] and $foo[21]=$too[13] and $foo[22] =$too[14]
and $foo[31] = $too[29] .
do you have any ideas?!
I thanks you in advance
-Amir
------------------------------
Date: Mon, 01 Oct 2007 16:33:49 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: constraints in perl
Message-Id: <fdr0ct$ocj$1@nserver.hrz.tu-freiberg.de>
Amir wrote:
> hi,
> I have a small question
> if I have a variable called $foo , and I want to check that this
> variable "bits" 20-23 and 31 is equal to other variable $too "bits"
> 12-14 and 29,respectively.
> I mean $foo[20]=$too[12] and $foo[21]=$too[13] and $foo[22] =$too[14]
> and $foo[31] = $too[29] .
> do you have any ideas?!
Perl has almost the same bitwise operators as
C/C++ (and others) has/have, therefore you'd
write the same kind, eg.:
...
my ($foo,$too) = (0x12345678, 0x87654321);
my $mask = (7 << 20) | (1 << 31);
my $both = $foo & $too & $mask;
printf "mask:\t%032b\nfoo:\t%032b\ntoo:\t%032b\n", $mask, $foo, $too;
printf "foo&too&mask:\n\t%032b (%d)\n", $both, $both;
...
Regards
M.
------------------------------
Date: Mon, 01 Oct 2007 15:32:11 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: constraints in perl
Message-Id: <470104fb$0$13939$fa0fcedb@news.zen.co.uk>
Amir wrote:
> hi,
> I have a small question
> if I have a variable called $foo , and I want to check that this
> variable "bits" 20-23 and 31 is equal to other variable $too "bits"
> 12-14 and 29,respectively.
> I mean $foo[20]=$too[12] and $foo[21]=$too[13] and $foo[22] =$too[14]
> and $foo[31] = $too[29] .
> do you have any ideas?!
I'd look at "bitwise operators" in `perldoc perlop`. Use of shift and
bitwise 'and' should get you to the point where you can compare values.
perl -e 'print 12>>2==3?"true\n":"false\n"'
true
perl -e '$x=4;$y=($x&12)>>2;print "$y\n"'
1
------------------------------
Date: Mon, 01 Oct 2007 14:35:43 -0000
From: Amir <sting.t2@gmail.com>
Subject: Re: constraints in perl
Message-Id: <1191249343.704676.83720@22g2000hsm.googlegroups.com>
On Oct 1, 4:32 pm, Ian Wilson <scoblo...@infotop.co.uk> wrote:
> Amir wrote:
> > hi,
> > I have a small question
> > if I have a variable called $foo , and I want to check that this
> > variable "bits" 20-23 and 31 is equal to other variable $too "bits"
> > 12-14 and 29,respectively.
> > I mean $foo[20]=$too[12] and $foo[21]=$too[13] and $foo[22] =$too[14]
> > and $foo[31] = $too[29] .
> > do you have any ideas?!
>
> I'd look at "bitwise operators" in `perldoc perlop`. Use of shift and
> bitwise 'and' should get you to the point where you can compare values.
>
> perl -e 'print 12>>2==3?"true\n":"false\n"'
> true
>
> perl -e '$x=4;$y=($x&12)>>2;print "$y\n"'
> 1
I was looking at bitwise and shift operators, but the problem is the
Constraint solver that I'm working with becomes very 'heavy' when I
use shift operator, hence, I'm looking for alternative way to solve
this...
------------------------------
Date: Mon, 01 Oct 2007 16:59:31 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: constraints in perl
Message-Id: <fdr1t3$on3$1@nserver.hrz.tu-freiberg.de>
Amir wrote:
> I was looking at bitwise and shift operators, but the problem is the
> Constraint solver that I'm working with becomes very 'heavy' when I
> use shift operator, hence, I'm looking for alternative way to solve
> this...
Can you explain why? Couldn't you
just compare the characters from
the bitwise representation, like:
...
my $f1 = join '', (split //, sprintf "%032b", $foo)[20..23, 31];
my $t1 = join '', (split //, sprintf "%032b", $too)[12..15, 29];
if($f1 eq $t1) {
print "bit are equal: $f1"
}
else {
print "bits are not equal $f1; $t1"
}
...
Regards
M.
------------------------------
Date: Mon, 01 Oct 2007 12:43:43 -0000
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: in what array do all the $1,$2,... live?
Message-Id: <1191242623.382588.170810@50g2000hsm.googlegroups.com>
On Sep 30, 3:03 am, jida...@jidanni.org wrote:
> What is the name of the array where all the $1,$2,... live?
> Or do I really need to gather them up manually:
> @all_the_matches=($1,$2,$3,$4,$5,...);
> man perlvar doesn't mention it.
This has been discussed here recently
http://groups.google.com/group/comp.lang.perl.misc/tree/browse_frm/thread/66e4e634e618da51/8b84cfd95af097ce
------------------------------
Date: Mon, 01 Oct 2007 07:34:57 -0700
From: lerameur <lerameur@yahoo.com>
Subject: Re: looping questions
Message-Id: <1191249297.927130.144610@w3g2000hsg.googlegroups.com>
On Sep 28, 4:56 pm, gba...@hiwaay.net (Greg Bacon) wrote:
> In article <1191010028.753764.76...@d55g2000hsg.googlegroups.com>,
> lerameur <leram...@yahoo.com> wrote:
>
> : for my $hours ('00'..'23') {
> : [...]
> : $hours++;
> : }
>
> Your code is doing twice as much work as necessary to compute
> the values of $hours:
>
> 1. Your for loop sets up a loop over '00' .. '23'
> 2. You increment $hours at the end of each iteration,
> but the value is ignored.
>
> You can remove the line with the increment.
>
> : $file23 = glob("$timestamp2$hours*") ;
>
> What if there's more than one match?
>
> : if ($file23 == 1){
> : system(`cp /input/fttr/traffic/$file23 /input/$Out_directory `);
> : }
>
> I don't see how the condition could ever be true because your
> glob shouldn't match a file whose name is 1.
>
> Perl's system operator wants a command to run, e.g.,
>
> system("ls -l /etc/motd");
>
> Backticks (``) also want a command. The value of a command
> quoted with backticks is the output of running it. For example:
>
> $ perl -e 'print `echo 1 + 2 | bc` * 4, "\n"'
> 12
>
> You usually don't want to combine them as you've done because
> that would run one command and then attempt to run its output
> a second command, e.g.,
>
> $ perl -e 'system `echo ls /`'
>
> Consider the following improvements:
>
> for my $hours ('00' .. '23') {
> my $cmd = join " " => "cp",
> "/input/fttr/traffic/$timestamp2$hours*",
> "/input/$Out_directory";
>
> system $cmd;
> }
>
> You could even condense your code to a single command:
>
> my $base = "/input/fttr/traffic/$timestamp2";
> system join " " => "cp",
> map("$base$_*", '00' .. '23'),
> "/input/$Out_directory";
>
> Hope this helps,
> Greg
> --
> Some cause happiness wherever they go; others whenever they go.
> -- Oscar Wilde
Ok thanks
it was the if loop:
putting thiif s is good: ($file23){
k
------------------------------
Date: Sun, 30 Sep 2007 20:37:13 -0700
From: Mintcake <tony@skelding.co.uk>
Subject: Odd regex behavior
Message-Id: <1191209833.188732.72770@50g2000hsm.googlegroups.com>
I wouldd be grateful to anyone who can shed some light on the
unexpected
results from the regex in the following program.
#!/usr/local/bin/perl -l
use strict;
my $y = ' href="/foo/bar?d=1&c=2&f=1&cards=1" x="123"';
for ($y =~ /(\s+\w+=['"](.*?)["'])/gs)
{
print "1) $_";
print "2) [$1][$2]";
my $x = /(\w+)=['"](.*)["']/;
print "3) [$x] [$1][$2]";
my $x = /(\w+)=['"](.*)["']/;
print "4) [$x] [$1][$2]";
my $x = /(\w+)=['"](.*)["']/;
print "5) [$x] [$1][$2]";
print "";
}
__END__
The results I get are as follows
1) href="/foo/bar?d=1&c=2&f=1&cards=1"
2) [ x="123"][123]
3) [1] [href][/foo/bar?d=1&c=2&f=1&cards=1]
4) [1] [href][/foo/bar?d=1&c=2&f=1&cards=1]
5) [1] [href][/foo/bar?d=1&c=2&f=1&cards=1]
1) /foo/bar?d=1&c=2&f=1&cards=1
2) [href][/foo/bar?d=1&c=2&f=1&cards=1]
3) [] [href][/foo/bar?d=1&c=2&f=1&cards=1]
4) [] [href][/foo/bar?d=1&c=2&f=1&cards=1]
5) [] [=2&f=][]
1) x="123"
2) [=2&f=][]
3) [1] [x][123]
4) [1] [x][123]
5) [1] [x][123]
1) 123
2) [x][123]
3) [] [x][123]
4) [] [x][123]
5) [] [x][123]
Now I accept that this code is sloppy for several reasons but in my
defence I have
to say that it is not my code.
1. A while loop would probably be better than a foreach loop
2. The first regex is attempting to break the string in a list of
att="value" type
strings but is returning att="value" and "value" so the .*? should not
be parenthesized
3. No attempt is made to ensure that the same type of quote is used at
the start and
end of the value
The thing I cannot explain are the results from the second iteration
of the loop. The
same regex is executed three times and each time it fails (correctly),
however, the third
time the $1 and $2 values are overwritten. I have always believed
that the $digit variable
would be preserved if the regex failed to match. Reading the Camel
indicates that this
should indeed be the case.
No matter how many times the regex is executed within the loop it is
only on the final one
$1 and $2 are overwritten
------------------------------
Date: Mon, 1 Oct 2007 04:08:56 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Odd regex behavior
Message-Id: <fdprso$ri9$1@ml.accsnet.ne.jp>
On Sun, 30 Sep 2007 20:37:13 -0700, Mintcake wrote:
> I wouldd be grateful to anyone who can shed some light on the
> unexpected
> results from the regex in the following program.
>
> #!/usr/local/bin/perl -l
>
> use strict;
Adding the line
use warnings;
to your script gives the answer to your problem.
------------------------------
Date: Mon, 01 Oct 2007 06:34:42 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Odd regex behavior
Message-Id: <1191245682.862600.149900@w3g2000hsg.googlegroups.com>
On Sep 30, 11:37 pm, Mintcake <t...@skelding.co.uk> wrote:
> I wouldd be grateful to anyone who can shed some light on the
> unexpected
> results from the regex in the following program.
>
> #!/usr/local/bin/perl -l
>
> use strict;
Why are you asking people for help before asking Perl for help? Why
haven't you enabled warnings?
>
> my $y = ' href="/foo/bar?d=1&c=2&f=1&cards=1" x="123"';
>
> for ($y =~ /(\s+\w+=['"](.*?)["'])/gs)
> {
> print "1) $_";
> print "2) [$1][$2]";
>
> my $x = /(\w+)=['"](.*)["']/;
> print "3) [$x] [$1][$2]";
>
> my $x = /(\w+)=['"](.*)["']/;
> print "4) [$x] [$1][$2]";
>
> my $x = /(\w+)=['"](.*)["']/;
> print "5) [$x] [$1][$2]";
>
> print "";}
>
> __END__
> Now I accept that this code is sloppy for several reasons but in my
> defence I have to say that it is not my code.
>
> 1. A while loop would probably be better than a foreach loop
No, not probably. Definitely. They do not do the same thing at all
in this case, because m//g has very different meanings when evaluated
in a list vs a scalar context.
> The thing I cannot explain are the results from the second
> iteration of the loop. The same regex is executed three times
No it's not. It's only executed once, because you evaluated it in a
list context and then iterated over the results of that one
evaluation, rather than iterating it repeatedly (and progressively) in
a scalar context.
Paul Lalli
------------------------------
Date: Mon, 01 Oct 2007 06:57:29 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Odd regex behavior
Message-Id: <1191247049.499322.271540@w3g2000hsg.googlegroups.com>
On Oct 1, 9:34 am, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 30, 11:37 pm, Mintcake <t...@skelding.co.uk> wrote:
>
> > I wouldd be grateful to anyone who can shed some light on the
> > unexpected results from the regex in the following program.
> > my $y = ' href="/foo/bar?d=1&c=2&f=1&cards=1" x="123"';
>
> > for ($y =~ /(\s+\w+=['"](.*?)["'])/gs)
> > {
> > print "1) $_";
> > print "2) [$1][$2]";
>
> > my $x = /(\w+)=['"](.*)["']/;
> > print "3) [$x] [$1][$2]";
>
> > my $x = /(\w+)=['"](.*)["']/;
> > print "4) [$x] [$1][$2]";
>
> > my $x = /(\w+)=['"](.*)["']/;
> > print "5) [$x] [$1][$2]";
>
> > print "";}
My profuse apologies. I completely misparsed what your post was
getting at, and came back with a completely wrong answer. Having run
your code, I am also confused as to what's happening. How is $1 being
set to '=2&f=' and how is $2 being undefined, especially seeing as how
as you said, the pattern match is failing. I'm going to keep staring
at it, but I look forward to other responses to this thread. . .
Paul Lalli
------------------------------
Date: Mon, 01 Oct 2007 14:35:49 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Odd regex behavior
Message-Id: <13g21e57phng8d1@corp.supernews.com>
Looks like you've found a bug. Please file a report!
Greg
--
When man attempts to rise above Nature, he usually falls below it.
-- Sherlock Holmes
------------------------------
Date: Mon, 01 Oct 2007 11:23:55 +0100
From: Paul Marquess <paul.marquess@btinternet.com>
Subject: Re: Problem installing IO::Compress::Base
Message-Id: <4700cabd$0$7365$4d4eb98e@read.news.uk.uu.net>
Ben Morrow wrote:
>
> Quoth John Oliver <joliver@john-oliver.net>:
> <snip>
>> # Failed test (t/01misc.t at line 29)
>> # You don't have the XS version of Scalar::Util
>
> Seems fairly self-explanatory to me... you need to (re-)install
> Scalar::Util, so you get the XS version.
>
> Arguably IO-Compress-Base ought to depend on Task::Weaken, which is
> supposed to fix this problem; I guess Paul is more interested in not
> introducing new potential problems.
Having a dependency on Task::Weaken would only make sense if I was using
weaken, which I'm not. I use Scalar::Util for readonly
Paul
------------------------------
Date: Mon, 01 Oct 2007 03:49:16 -0700
From: anil <anilkumar.iitm@gmail.com>
Subject: Re: Small doubt in perl
Message-Id: <1191235756.882573.15950@50g2000hsm.googlegroups.com>
On Sep 28, 8:19 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Michele Dondi <bik.m...@tiscalinet.it>:
>
> > On Wed, 26 Sep 2007 22:55:59 -0700, anil <anilkumar.i...@gmail.com>
> > wrote:
>
> > >system("sample.sh");
> > >system("java test");
>
> > >In the "sample.sh" i have set some environmental variables, but the
> > >environment variables which are set in the sample.sh are not used by
> > >the java pgm.
>
> > >Is there any other way to achieve this functionality?
>
> > system qw/sh -c/ => 'sample.sh; java test';
>
> This won't work. sample.sh is still run as a subprocess of the shell.
> You need to locate the shell used for sample.sh (I'll assume /bin/sh),
> and run
>
> system '/bin/sh', -c => '. sample.sh; java test';
>
> Note the '.', which makes the shell run the script in the same process.
> It may be better to use
>
> system '/bin/sh', -c => '. sample.sh; exec java test';
>
> which will save a fork.
>
> Ben
For curiosity, Is there any method to run on windows also, suppose we
have sample.bat instead of sample.sh ?
------------------------------
Date: Mon, 01 Oct 2007 15:12:15 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Small doubt in perl
Message-Id: <p1s1g3h23crjh9aidfp5jdq4cbrumnpsdh@4ax.com>
On Mon, 01 Oct 2007 03:49:16 -0700, anil <anilkumar.iitm@gmail.com>
wrote:
>> This won't work. sample.sh is still run as a subprocess of the shell.
>> You need to locate the shell used for sample.sh (I'll assume /bin/sh),
>> and run
>>
>> system '/bin/sh', -c => '. sample.sh; java test';
>>
>> Note the '.', which makes the shell run the script in the same process.
>> It may be better to use
>>
>> system '/bin/sh', -c => '. sample.sh; exec java test';
>>
>> which will save a fork.
>>
>> Ben
>
>For curiosity, Is there any method to run on windows also, suppose we
>have sample.bat instead of sample.sh ?
Exactly the same except that I don't know whether Win's scripting
language allow for the equivalent of sourcing. If it's just a matter
of setting some environment variables one may avoid a separate shell
script and massage %ENV directly from perl, though.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 01 Oct 2007 07:25:00 -0700
From: anil <anilkumar.iitm@gmail.com>
Subject: Re: Small doubt in perl
Message-Id: <1191248700.873437.30730@22g2000hsm.googlegroups.com>
On Oct 1, 6:12 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Mon, 01 Oct 2007 03:49:16 -0700, anil <anilkumar.i...@gmail.com>
> wrote:
>
>
>
> >> This won't work. sample.sh is still run as a subprocess of the shell.
> >> You need to locate the shell used for sample.sh (I'll assume /bin/sh),
> >> and run
>
> >> system '/bin/sh', -c => '. sample.sh; java test';
>
> >> Note the '.', which makes the shell run the script in the same process.
> >> It may be better to use
>
> >> system '/bin/sh', -c => '. sample.sh; exec java test';
>
> >> which will save a fork.
>
> >> Ben
>
> >For curiosity, Is there any method to run on windows also, suppose we
> >have sample.bat instead of sample.sh ?
>
> Exactly the same except that I don't know whether Win's scripting
> language allow for the equivalent of sourcing. If it's just a matter
> of setting some environment variables one may avoid a separate shell
> script and massage %ENV directly from perl, though.
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
I have searched in the net and i found the solution we have to
replace ; with & in the above system command. Thanks for all your
valuable replies...
------------------------------
Date: Mon, 1 Oct 2007 02:24:37 +0200 (CEST)
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
Message-Id: <slrnfg0fhu.6r8.allergic-to-spam@no-spam-allowed.org>
On 2007-09-30, Big and Blue <No_4@dsl.pipex.com> wrote:
> Jim Cochrane wrote:
>> I'm stumped - trying to get rid of a warning message with code based on
>> this example snippet from the "Perl Cookbook" book:
>
> Your problem has nothing at all to do with fcntl
>
> "use strict" and "use warnings" would have shown you the problem.
You've missed the mark and have things pretty much reversed. And you
don't appear to have read my original message very well. I'll summarize
what I found, below.
>
>> $lags = "";
>> fcntl(HANDLE, F_GETFL, $flags) or die "Couldn't get flags: $!\n";
>> $flags |= O_NONBLOCK;
You've excerpted my typed-in quote from the Perl Cookbook, rather
than the code at the bottom of my message that I was actually running
(and which does 'use strict' and 'use warnings').
[From my original message: "(I've typed the above by hand and shortened
the error messages - sorry for any typos.)" and "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."
]
>
> It's $flags which is undefined. You've set $lags, not $flags (and
> setting it to 0 rather than "" would make far more sense).
>
>> You don't have to check for "defined" on the return from
>> "fcntl".
>
> You aren't even checking the return result from fcntl. You are just
> ignoring it completely (you're calling it in a void context, i.e. not
> assigning the return value to anything).
If you're going to respond to a message, please read it properly first,
take some time to understand the issue, and do a better job of quoting
from it.
What I found was that the warning message occurs because the 'use
warnings' facility does not like the use of the | operator with the
non-numeric value assigned to the $flags variable by the first fcntl
call. The best solution appears to be to insert a local 'no warnings
"numeric"' line before the "offending" code. (I posted a followup a
couple days ago that incorrectly stated that deleting:
$flags |= O_NONBLOCK;
and instead doing the or in the 2nd fcntl call:
fcntl($file, F_SETFL, $flags | O_NONBLOCK) or die "Could not set flags: $!\n";
got rid of the warning; but it doesn't - I had forgotten to remove the
'no warnings...' line when I tried that.)
For reference, here's my test code posted in my original message:
------------------------------------------------------------------
#!/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";
------------------------------------------------------------------
--
------------------------------
Date: Sun, 30 Sep 2007 21:40:54 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Using fcntl and |= - "Argument .... isn't numeric in bitwise or ..."
Message-Id: <Mu2dnWGQQPlDlJ3anZ2dnUVZ8q6unZ2d@pipex.net>
Jim Cochrane wrote:
> I'm stumped - trying to get rid of a warning message with code based on
> this example snippet from the "Perl Cookbook" book:
Your problem has nothing at all to do with fcntl
"use strict" and "use warnings" would have shown you the problem.
> $lags = "";
> fcntl(HANDLE, F_GETFL, $flags) or die "Couldn't get flags: $!\n";
> $flags |= O_NONBLOCK;
It's $flags which is undefined. You've set $lags, not $flags (and
setting it to 0 rather than "" would make far more sense).
> You don't have to check for "defined" on the return from
> "fcntl".
You aren't even checking the return result from fcntl. You are just
ignoring it completely (you're calling it in a void context, i.e. not
assigning the return value to anything).
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 893
**************************************