in reply to Re: What does return() mean?
in thread What does return() mean?

It doesn't answer my question... I want to know what return () does... For example, if I'm correct, return [] returns an array ref right? So, does return () return a subroutine ref?

Replies are listed 'Best First'.
Re^3: What does return() mean?
by davido (Cardinal) on Oct 27, 2014 at 22:18 UTC

    It does the same as return;, which is an empty list in list context, and the return value evaluates to undef in scalar context.


    Dave

Re^3: What does return() mean?
by AnomalousMonk (Archbishop) on Oct 28, 2014 at 02:41 UTC

    If you actually want to return a code/subroutine reference see sub or the  \ operator (see Symbolic Unary Operators in perlop)

    c:\@Work\Perl>perl -wMstrict -le "sub S { return sub { print qq{hiya $_[0]}; }; } ;; my $coderef = S(); $coderef->('sailor') " hiya sailor

Re^3: What does return() mean?
by Anonymous Monk on Oct 28, 2014 at 02:53 UTC
Re^3: What does return() mean?
by Discipulus (Canon) on Oct 28, 2014 at 08:39 UTC
    It doesn't answer my question..

    this is because you have not formulated the right question, as the agent Spooner in I robot, dear.

    Consider this other formulation: 'What is the difference between return (); and return [];?' For completness you have to know there is also return {}; that returns a reference to an anonymous hash.

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.