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