You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by James Ponder <ja...@db.com> on 2002/07/09 15:43:35 UTC
returning lists from subroutines
Hi,
I think there may be a bug in your subroutine handling code, or at least an unexpectedness that I can't find documented:
[$ sub testsub $]
[-
my @a = ('foo', 'bar');
return @a;
-]
[$ endsub $]
Whatever context this subroutine is called in, the return statement is always evaluated in scalar context, so if I called this with:
my @b = testsub();
@b now contains just '2', rather than the two list elements.
Best wishes, James
--
James Ponder
--
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: returning lists from subroutines
Posted by Gerald Richter <ri...@ecos.de>.
Hi,
>
>
> Whatever context this subroutine is called in, the return statement is
always evaluated in scalar context, so if I called this with:
>
That's true. I think I should fix it and make behave it like in Perl.
BTW. 1.3.4 isn't able to return values from subs at all (only as parametrer
per reference) and when I designed 2.0 I wanted to change this, but didn't
have done any test on it so far. So it more suprising that it works at all
:-)
I put it on the TODO list, so we get correctly working return args for the
next release
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org