[sf-perl] Return from a function

Randal L. Schwartz merlyn at stonehenge.com
Thu Feb 28 11:23:49 PST 2008


>>>>> "nheller" == nheller  <nheller at silcon.com> writes:

nheller> I was always under the assumption that Perl (like C) returns a single
nheller> value from a function.  I seems like this is not true as it looks
nheller> like the following function returns 3 values.  How could this be?

You might have got this impression from the early Learning Perl editions,
where we never show a list-context return because it wasn't needed for any of
the exercises.

But in fact, the last expression evaluated in the subroutine is evaluated in
the context of the caller, so if you're assigning it to a literal list, or
perhaps an array variable, then a list of values will be returned.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


More information about the SanFrancisco-pm mailing list