in reply to Re: A list assignment gotcha
in thread Not understanding 2 sentences in perldoc
You can use [3, 2, 1] on the RHS, as well.#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: A list assignment gotcha (Updated)
by LanX (Saint) on Jul 30, 2020 at 14:48 UTC | |
by jcb (Parson) on Jul 31, 2020 at 01:32 UTC | |
by LanX (Saint) on Jul 31, 2020 at 02:20 UTC | |
by jcb (Parson) on Aug 01, 2020 at 02:10 UTC | |
by LanX (Saint) on Aug 01, 2020 at 09:26 UTC |