GhodMode has asked for the wisdom of the Perl Monks concerning the following question:
Why doesn't $ret_val (scalar) in the following code get the value 4: the number of elements in the list returned by the test subroutine? What's happening here? ...
Invulnerable. Unlimited XP. Unlimited Votes. I must be...perl -e ' sub test { my @array = qw{ fish, chicken, pork }; return @array,1; } # $ret_val gets the value 1; $ret_val = test(); # @ret_val get each item in @array and the last # index in @ret_val is 1 @ret_val = test(); print $ret_val . "\n"; print @ret_val . "\n"; for ( @ret_val ) { print $_ . "\n" }; ' 1 4 fish, chicken, pork 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: subroutine list return
by merlyn (Sage) on Jun 24, 2003 at 18:03 UTC | |
|
Re: subroutine list return
by Tomte (Priest) on Jun 24, 2003 at 18:04 UTC | |
|
Re: subroutine list return
by Mr. Muskrat (Canon) on Jun 24, 2003 at 18:10 UTC | |
|
Re: subroutine list return
by NetWallah (Canon) on Jun 25, 2003 at 02:45 UTC | |
|
Re: subroutine list return
by NetWallah (Canon) on Jun 25, 2003 at 01:06 UTC | |
by chromatic (Archbishop) on Jun 25, 2003 at 01:25 UTC |