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.

--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re: function parameter assignment question by blazar
in thread function parameter assignment question by perlfan99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.