Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: What does return() mean?

by hippo (Bishop)
on Oct 27, 2014 at 21:24 UTC ( [id://1105212]=note: print w/replies, xml ) Need Help??


in reply to What does return() mean?

Like all Perl functions, return is documented. Have a read of that and see if it answers your questions.

Replies are listed 'Best First'.
Re^2: What does return() mean?
by yistaaa (Initiate) on Oct 27, 2014 at 22:07 UTC
    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?

      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

      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

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found