#!/usr/bin/perl
use strict;
use warnings;
my @a = qw/a b c/;
(@a) x= 3;
print join(", ", @a), "\n";
I would expect the code above to print "a, b, c, a, b, c, a, b, c\n"
, but instead it dies with the message:
Can't modify private array in repeat (x) at z.pl line 7, near "3;"
This seems odd because the X <op>= Y
are documented as being equivalent to X = X <op> Y
, and the following code works as I expect it to:
#!/usr/bin/perl
use strict;
use warnings;
my @a = qw/a b c/;
(@a) = (@a) x 3;
print join(", ", @a), "\n";
Is this a bug in Perl or am I misunderstanding what should happen here?