开发者

Why does this Perl function return a value?

开发者 https://www.devze.com 2023-01-18 00:21 出处:网络
$hi = do_this(\'asdf\'); sub do_this { $blob{\'f\'} = { \'k\' => \'j\' }; } print $hi->{\'k\'}; # prints j
   $hi = do_this('asdf');

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

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

since do_开发者_如何学Gothis doesn't return anything, how does it still print j?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消