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

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -