Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this Perl function return a value?

Tags:

perl

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

like image 219
user318747 Avatar asked Sep 24 '10 18:09

user318747


2 Answers

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

like image 174
Jim Garrison Avatar answered Oct 20 '22 16:10

Jim Garrison


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

like image 42
Chas. Owens Avatar answered Oct 20 '22 17:10

Chas. Owens