[Chicago-talk] return values

Randal L. Schwartz merlyn at stonehenge.com
Tue Dec 30 14:07:40 CST 2003

>>>>> "Dooley," == Dooley, Michael <Dooley.Michael at con-way.com> writes:

Dooley,> if you have multiple return values do you have to use an array to collect
Dooley,> them? or can you get each return value in is own variable off the jump?

Dooley,> sub stuff {
Dooley,> $a=1;
Dooley,> $b=2;
Dooley,> return ($a, $b);
Dooley,> }

Dooley,> @c=stuff

Dooley,> so
Dooley,> $c=1st return value
Dooley,> $d=2nd return value

The last expression of a subroutine is evaluated in the caller's context
(list or scalar or void).  So that'd look like:

  @c = stuff();

And $c[0] would be 1, and $c[1] would be 2.  You can also use
a list assignment:

  ($c, $d) = stuff();

and get what you suggested.

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 Chicago-talk mailing list