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

my ($a,$b) seems to be handled like a shorthand for my ($a,$b)=(undef,undef)

What my() returns in scalar context (the last value it would normally return in list context) is unrelated to what list assignment returns in scalar context (the count of items returned by its RHS).

>perl -wE"$r = \my ($x,$y,$z); $$r = '!'; say $x; say $y; say $z" Use of uninitialized value $x in say at -e line 1. Use of uninitialized value $y in say at -e line 1. ! >perl -wE"my $c = my ($x, $y, $z) = (undef, undef); say $c" 2

Replies are listed 'Best First'.
Re^2: why doesn't "my ($a,$b)" return a list?
by LanX (Saint) on Aug 19, 2010 at 15:01 UTC
    no idea what you are talking about, I'm getting exactly the same results in list context like with an implicit assignment of undefs.

    Using deref-operator \ is another case .

    DB<7> sub tst2 {print scalar @_ } DB<8> tst2( my ($a,$b,$c,$d)) 4 DB<10> tst2( my ($a,$b,$c)) 3 DB<11> tst2( my ($a,$b)) 2 DB<12> tst2( my ($a)) 1 DB<13> tst2( my ($a,$b,$c,$d)=(undef,undef,undef,undef)) 4
    UPDATE: ah sorry never mind!

    Cheers Rolf