in reply to function parameter assignment question
i have two functions, only difference is the how parameter is assigned "my $data = @_ vs. my ($data) = @_" (for me, they are same), i don't know why test1 gives the correct result, but test2 doesn't, it always prints out the size of the parameters.
(additional emphasis by me.)
I personally believe that (leaving aside the fact that you had asked the very same question less than one month ago - for which ikegami has had to point out the answer he gave back then) you should strongly refrain from analyzing Perl code in terms of what that may possibly seem to you in favour of what that Perl actually does all the time: here in particular, the "problem" has nothing to do with subs or parameter assignment but with a basic (and thus one you should get rapidly acquainted with) feature of the Perl programming language - dwimmy differentiation of behaviour based on context.
C:\temp>perl -E "my @l=qw/foo bar baz/; my ($x)=@l; my $y=@l; say for +$x, $y" foo 3
See? No sub at all! End of story: parens do matter.
|
|---|