A bit trickier than I originally thought. What I didn't expect was the need to use the :lvalue on both the listifier and constructor.
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
{ package L;
use overload
'+=' => sub {
my ($self, $inc) = @_;
$_ += shift @$inc for @$self;
};
sub new :lvalue {
bless $_[1], $_[0]
}
}
sub L :lvalue { 'L'->new(\@_) }
my ($x, $y, $z) = (10, 20, 30);
L($x, $y, $z) += L(3, 2, 1);
say "$x $y $z"; # 13 22 31
You can use
[3, 2, 1] on the RHS, as well.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]