perl 101 subroutine and return value -


i don't understand how return 4 answer. not sure happening inside subroutine.

  sub bar {@a = qw (10 7 6 8);} $a = bar();  print $a;   # outputs 4  

the subroutine called in scalar context. last statement in subroutine assignment @a, expression , becomes implied return value. in scalar context, evaluates number of elements returned assignment's right-hand side (which happens same number of elements in @a).


Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -