Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Useless use of string in return statement

by GrandFather (Saint)
on Apr 12, 2021 at 23:32 UTC ( [id://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 noname.pl line + 23. Useless use of string in void context at noname.pl 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 (Archbishop) 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
    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-23 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found