Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Situation where warning "Found = in conditional, should be" seems obsolete

by LanX (Saint)
on Feb 06, 2021 at 16:48 UTC ( [id://11127982]=note: print w/replies, xml ) Need Help??


in reply to Situation where warning "Found = in conditional, should be" seems obsolete

Background: Short circuit and and or are semantically like if and unless in Perl, IIRC it's even the same op code.

Personally I tend to avoid this C syntax outside one liners, where readability and maintenance are no issues.

Now this warning is intended for conditionals.

So if you don't like to straighten the syntax, you are free to disable this warning.

update

Especially chaining both operators without parens makes me second guessing precedence

$_ % 2 or $has_even = 1 and last

I don't wanna puzzle over such code.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re: Situation where warning "Found = in conditional, should be" seems obsolete
  • Download Code

Replies are listed 'Best First'.
Re^2: Situation where warning "Found = in conditional, should be" seems obsolete
by LanX (Saint) on Feb 06, 2021 at 18:07 UTC
    perlop is clear that and has higher precedence than or and this can be checked with B::Deparse and -p option

    $_ % 2 or ( $has_even = 1 and last )

    Like others already implied does $has_even = 1 and last not make much sense, since the assignment at LHS is always true.

    Furthermore is this a quite pathological case, because the part with the code-branch with higher precedence is never executed.

    compare

    DB<215> p 0 or 1 and 0 0 DB<216> p (0 or 1) and 0 1 DB<217>

    update
    DB<233> p 0 or 1 and die "never" 0 DB<234> p 0 or (1 and die "never") 0 DB<235> p (0 or 1) and die "never" 1never at (eval 265)[c:/Perl_524/lib/perl5db.pl:737] line 2. DB<236>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127982]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found