in reply to why doesn't "my ($a,$b)" return a list?

Prototype "$" imposes a scalar context on the corresponding expression in the parameter list. That means that my cannot possibly return a list. Without trying, I'd guess it returns the last of the values it would normally return. To avoid this problem, remove the prototype or use

tst(my $x, my $y);

(Spotty internet delayed my posting. Sorry for repeating what moritz covered.)

Replies are listed 'Best First'.
Re^2: why doesn't "my ($a,$b)" return a list?
by LanX (Saint) on Aug 19, 2010 at 14:53 UTC
    > Without trying, I'd guess it returns the last of the values it would normally return.

    nope my returns the number of declared variables, see the update in the OP.

    > To avoid this problem, remove the prototype

    prototype is not the problem.

    > or use use

    > tst(my $x, my $y);

    which unfortunately results in tst(state $x, state $y); in my case!

    Cheers Rolf

      nope my returns the number of declared variables, see the update in the OP.

      Sorry, but you are mistaken.

      $ perl -wE'say(scalar(my ($x, $y)))' Use of uninitialized value $y in say at -e line 1.

      It doesn't return the count. Like the error message shows, it returns the last element it would have returned (as I had guessed).

      which unfortunately results in tst(state $x, state $y); in my case!

      Or

      &tst(state ($x, $y));

      But I prefer what you had over using "&".

        > Sorry, but you are mistaken.

        could be, I totally misread my tests!

        changing the prototype to (\@@) helped.

        Thanks! :)

        Cheers Rolf