[32937] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4213 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 15 11:09:19 2014

Date: Thu, 15 May 2014 08:09:03 -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           Thu, 15 May 2014     Volume: 11 Number: 4213

Today's topics:
    Re: Help with an operator precedence (?) puzzle <rweikusat@mobileactivedefense.com>
    Re: Help with an operator precedence (?) puzzle <rweikusat@mobileactivedefense.com>
    Re: Help with an operator precedence (?) puzzle <news@lawshouse.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 15 May 2014 15:11:15 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Help with an operator precedence (?) puzzle
Message-Id: <87k39nnncs.fsf@sable.mobileactivedefense.com>

Henry Law <news@lawshouse.org> writes:
> Perl 5.14 running on Ubuntu.  I'm fairly sure that the answer to this
> is operator precedence but I've looked at it and consulted perldoc
> until my brain hurts and I can't work it out. Could someone explain?

[...]

> #!/usr/bin/perl
> use strict;
> use warnings;
> use 5.010;
>
> sub tryit {
>   my ( $user, $conf, $parms ) = @_;
>   $@ = "reset_user: invalid parameters\n" and return if $parms==1;
>   $@ = "reset_user: '$user' doesn't exist\n" and return if $parms==2;
> }
>
> If I compile it Perl warns me: "Found = in conditional, should be ==
> at tryout.pl line 8."

$parms == 1 and $@ = "reset toastbrot" and return;

The second and-junctor is technically nonsense because the value
of its left-hand operand will always be true. The perl compiler was so
kind to assume that you meant to write something sensible and
accidentally forgot to put in the == which would have turned this into a
(still rather bizarre) test.

The easy way to avoid being told than one isn't making sense by a
computer is to stop confusing it (and the hypothetical maintencance
programmer would be very grateful for that), ie, use

sub tryit {
  my ( $user, $conf, $parms ) = @_;
  $@ = "reset_user: invalid parameters\n", return if $parms==1;
  $@ = "reset_user: '$user' doesn't exist\n",  return if $parms==2;
}

instead.

NB: 'Mr Law' is unlikely to see this but I hope it may be useful for
someone else. Usually, I wouldn't write it in this style ...


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

Date: Thu, 15 May 2014 15:20:57 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Help with an operator precedence (?) puzzle
Message-Id: <87fvkbnmwm.fsf@sable.mobileactivedefense.com>

tmcd@panix.com (Tim McDaniel) writes:
> In article <mM2dna38mqJp2ezOnZ2dnUVZ8rOdnZ2d@giganews.com>,
> Henry Law  <news@lawshouse.org> wrote:

[...]

>>But line 9 is virtually identical, except for the presence of an 
>>interpolated variable, and it compiles clean!  Blowed if I know why.
>
> At a guess, the "Found = in conditional" warning is a heuristic that
> gets confused somehow by an interpolated string in particular.  That
> is, it's the lack of a message line 9 that is the problematic one, not
> line 8.

This warning is produced by a routine named S_scalarboolean (op.c) and
it warns if it encounters a scalar assignment whose right operand is a
constant (in boolean context).


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

Date: Thu, 15 May 2014 15:55:12 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Help with an operator precedence (?) puzzle
Message-Id: <Nf-dnQjud5LPSOnOnZ2dnUVZ7tednZ2d@giganews.com>

On 15/05/14 15:11, Rainer Weikusat wrote:
> NB: 'Mr Law' is unlikely to see this but I hope it may be useful for
> someone else. Usually, I wouldn't write it in this style ...

Eh?  Phwatttt?  What on earth makes you say that, I wonder.

The other stuff you wrote, of which I read every word, was helpful.

-- 

Henry Law            Manchester, England


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 4213
***************************************


home help back first fref pref prev next nref lref last post