>>>>> "BM" == Brandon McCaig <bamcc...@gmail.com> writes:

  BM> 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.

  BM> I didn't realize this was an existing thread. In Google Mail it
  BM> 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.

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

but returning an array was never mentioned before. it is a very
different beast.

  >> 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.

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

as is documented and as i said. the () are meaningless there. they just
group. as i keep saying parens in general in perl are for grouping and
syntax and not much else (to most newbie's surprise). they don't make
lists. they are useful to delineate where a list is (that is grouping).

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

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

undef is not 0.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

--
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