tags:

views:

126

answers:

2
   $hi = do_this('asdf');

   sub do_this
   {
       $blob{'f'} = {
          'k' => 'j'
      };
   }

   print $hi->{'k'};
   # prints j

since do_this doesn't return anything, how does it still print j?

+22  A: 

http://perldoc.perl.org/functions/return.html

In the absence of an explicit return, a subroutine, eval, or do FILE automatically returns the value of the last expression evaluated

Jim Garrison
also `do BLOCK` and any other block structure when it is in non-void context
Eric Strom
+4  A: 

All Perl 5 subroutines return the last value of the last statement executed.

Chas. Owens
...assuming they don't hit a `return` statement
friedo
@friedo: If they hit a `return` statement, what's the last statement executed? :P
Jon Purdy
Well, the less weird way to say that is the result of the last evaluated expression. That might not be the "last value" of since subroutines can return multiple items.
brian d foy