develooper Front page | perl.perl5.porters | Postings from October 2016

Re: (\@a) = \($x,$y) in non-void context

Thread Previous | Thread Next
David Nicol
October 21, 2016 21:49
Re: (\@a) = \($x,$y) in non-void context
Message ID:
On Fri, Oct 21, 2016 at 10:08 AM, Dave Mitchell <> wrote:
>  I think it's a bug that 'empty' scalars before a slurpy aren't passed
> through:
>     @a = (($a,$b,$c,@d) = 1..2);  # @a contains 2 elements: $c not passed

Hey you're right! Even when $c was previously defined and loses its
value, making $c a "value assigned to" which should get passed along.

> and though rarer, I think for consistency, scalars following a slurpy
> should be visible too:
>     @a = (($a,$b,@c,$d) = 1..2);  # @a contains 2 elements: $d not passed

I can't think of any kind of situation in which the current behavior
would be useful instead of confusing. Anyone writing either of these
things is expecting ... what, exactly? That $a and $b get 1 and 2
assigned to them, *c and *d get cleared, and why would they want @a
right-padded with undefs? OTOH, why would they object to the padding,
since that's what the documentation says should happen?

> I've just pushed a branch for smoking, smoke-me/davem/aassign
> that has two main commits: the first optimises the hell out of aggregate
> assignment (which I've been working on for the last 3 weeks and why I
> keep spotting these edge cases), and the second fixes the above according
> to my interpretation of what's right.

think, think ... maybe the rightward scalars are in there because the
coder didn't want to declare another "my" because their local style
guidelines mandate that all variable declarations are supposed to
happen in exactly one my declaration?

     sub noobfu {
          @args_copy = my ($obj,$p1, @c, $d) = @_;

surprisingly right-padding @args_copy with undefined values in this
contrived case is the risk I have identified and hereby present for

David Nicol

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About