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

> 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

Replies are listed 'Best First'.
Re^3: why doesn't "my ($a,$b)" return a list?
by ikegami (Patriarch) on Aug 19, 2010 at 15:19 UTC

    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