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

Re: Useless use of string in return statement

by GrandFather (Saint)
on Apr 12, 2021 at 23:32 UTC ( #11131160=note: print w/replies, xml ) Need Help??

in reply to Useless use of string in return statement

I get:

Possible precedence issue with control flow operator at line + 23. Useless use of string in void context at line 23.

for the return $result{'message'} ... line, which makes sense. Remember or is low precedence so the compiler sees:

(return $result{'message'}) or "$result{'api-key'}:$result{'session'}" +;

High precedence || would fix the problem

Update: note that I'm using Perl v5.32.0.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Useless use of string in return statement
by syphilis (Bishop) on Apr 13, 2021 at 09:40 UTC
    I can never remember the rules of precedence, so I just remove the relevance of such considerations by using brackets to make my intentions clear:
    C:\>perl -MO=Deparse,-p -e "return $x or $y" ((return $x) or $y); -e syntax OK C:\>perl -MO=Deparse,-p -e "return ($x or $y)" (return ($x || $y)); -e syntax OK

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-05-15 01:11 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (150 votes). Check out past polls.