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
Post a Comment