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? | [reply] |
| [reply] [d/l] |
c:\@Work\Perl>perl -wMstrict -le
"sub S { return sub { print qq{hiya $_[0]}; }; }
;;
my $coderef = S();
$coderef->('sailor')
"
hiya sailor
| [reply] [d/l] [select] |
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? Yes, [ ] is an array ref, and no () is not a reference of any kind (not a subroutine ref) References are explained in perlreftut#Making References , references quick reference
These are all the same (as documente in return, they return nothing (empty list) or undef , depending on context (list or scalar) )
sub roy { return; }
sub roy { return }
sub roy { return(); }
sub roy { return() }
sub roy { return () }
These are all the same (return an array ref)
sub roy { return []; }
sub roy { return [] }
sub roy { return([]); }
sub roy { return([]) }
sub roy { return ([]) }
See Tutorials: Context in Perl: Context tutorial, "List" Is a Four-Letter Word, Easy Reference for Contexts | [reply] [d/l] [select] |
| [reply] [d/l] [select] |