On Thu, Feb 10, 2011 at 10:20 PM, Uri Guttman <u...@stemsystems.com> wrote:
> this is all well documented. and i posted an explanation earlier in the
> thread.

I didn't realize this was an existing thread. In Google Mail it
appeared as a new thread.

>  BM> sub test3
>  BM> {
>  BM>     my @empty_array = ();
>
>  BM>     return @empty_array;
>  BM> }
>
> that is very different than the above two.

The point was to compare the results. It wasn't supposed to be the same. :-/

> have it by definition. the array is returned in scalar context and it
> has zero elements so the return value is 0. the rule is very simple: the
> return expression is evaluated in the caller's context. it is just as if
> you took the return expression and put it in an assignment.

I thought that Perl couldn't return arrays. I thought it could only
return scalars and lists. And so I believed that returning an empty
array would in fact return an empty list. The point was for that empty
list to become 0 in scalar context, which could be compared to the
subroutine that returned with `return ();`. The fact that the `return
();` example returned undef instead indicated to me that `return ();`
was equivalent to `return;`.

> these do the same thing:
>
> $scalar = test1() ;
> $scalar = () ;

I would have expected 0 from the latter of the two. :-/ I guess I
don't understand how Perl works after all. Better I find out this way
though. :P


-- 
Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to