develooper Front page | perl.perl5.porters | Postings from November 2010

[perl #77762] Fcntl -w causing perl script compile failures

Thread Next
From:
Father Chrysostomos via RT
Date:
November 28, 2010 13:26
Subject:
[perl #77762] Fcntl -w causing perl script compile failures
Message ID:
rt-3.6.HEAD-13564-1290979575-1946.77762-15-0@perl.org
On Mon Sep 20 12:33:23 2010, toddr@cpanel.net wrote:
> 
> On Sep 11, 2010, at 4:29 AM, Nicholas Clark wrote:
> 
> > Thanks for the report.
> >
> > It seems to be completely unrelated to Fnctl or any external module:
> >
> > $ ./perl -we 'sub A () {1}; if (0) {my $foo = A}'
> > $ ./perl -we 'sub A () {1}; if (0) {my $foo = A or die}'
> > Found = in conditional, should be == at -e line 1.
> > $
> 
> Nicholas, thanks for the reply. To rephrase:
> 
> As I understand it,
> 
> This warns because putting an or next to a constant assignment is
>    silly and potentially meant to be ==:
> $ ./perl -we 'my $foo = 1 or die'
> Found = in conditional, should be == at -e line 1.
> 
> So the issue is that Fcntl is inlining the subroutine calls into
>    constants, which makes
> 
> my $foo = Fcntl::F_GETFL() or die;
> 
> inline to
> 
> my $foo = 3 or die;
> 
> The code in question that brought this up needed to be cross platform.
>    I wasn't certain if Fcntl sub calls would always give sane answers
>    for these constants and was checking their values. I guess I just
>    need to trust that it will always return a valid constant for the
>    given platform?

With this four-line patch:

$ ./perl -we 'sub A () {1}; if (0) {my $foo = A or die}'
$ ./perl -we 'sub A () {1}; if (0) {my $foo = 1 or die}'
Found = in conditional, should be == at -e line 1.

Since the value of a constant may not be known at the time the program
is written, it should be perfectly acceptable to do a constant
assignment in a conditional.

This just needs a test added, which I will do if this change is
acceptable. Is it?


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About