develooper Front page | perl.perl5.porters | Postings from May 2015

[perl #125286] Conditional 'return()' in function call

Thread Next
Daniel Șuteu
May 31, 2015 16:41
[perl #125286] Conditional 'return()' in function call
Message ID:
# New Ticket Created by  Daniel Șuteu 
# Please include the string:  [perl #125286]
# in the subject line of all future correspondence about this issue. 
# <URL: >

Let's assume the following code:


use 5.010;
use strict;
use warnings;

sub a {
    return "foo";

sub b {
    my ($x, $y) = @_;
    say $x;             # $x is "foo"
    say $y;             # $y is undefined

b(a() // return(), "bar");      # this fails
b(a() // return, "bar");        # this works
b(a() // (return()), "bar");    # this works


In the first call, the second parameter ($y) becomes undefined. This is triggered by the return keyword used with parentheses.

In the second call, after removing the parentheses, it seems to work correctly. Also, wrapping the return inside parentheses seems to work too.

As far as I tested, the issue can be reproduced only with the "return" keyword. It's reproducible with the following versions of Perl (and possible others): 5.14.4, 5.20.2, perl-5.22.0-RC2


Use of uninitialized value $y in say at line 12.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About