Re: $_ read-only issue on "21". Not new, always has been

[email protected] (Aristotle Pagaltzis via perl5-porters) Sat, 18 Apr 2026 04:47:48 +0200
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
* Johan Vromans <[email protected]> [2026-04-16 19:31]:
> On Thu, 16 Apr 2026 09:30:04 +0200, "H.Merijn Brand" wrote:
> > Weird is that - at least on my side - this read-only fail *ONLY*
> > happens on "21" If I leave out "21", all PASSs on ALL perl releases
>
> Apparently "21" is a constant (readonly), while the other are ranges
> that are not marked readonly.

A range compiles to a fully const AV, but the enteriter op (i.e.
foreach) makes a copy of that before it iterates over it, and the copy
is mutable.

A single integer literal compiles to a const IV which enteriter just
binds to the loop variable directly.

No idea why the difference.

-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>