These variables are read-only ...

I suspect that statement can be found at least back to 5.10 and maybe to 5.8.

I checked my local perlvar for the versions I have in captivity, 5.8-14, and this assertion is in each one. (I didn't bother to check all the on-line perlvar versions; I assume it's in all those as well.)

For all my initial shock at seeing an old, dear friend abused in this way, I'm not so sure | I do not think it's classifiable as a bug. After all,  $1 is just a symbol, and aliasing is supposed to enable one to treat one symbol exactly like another. That's what's going on in the for-loop: the perfectly mutable  @line array elements are successively aliased to the  $1 symbol, to which one can do anything it's kosher to do to an element of the array. One can see this here:

c:\@Work\Perl>perl -wMstrict -le "my @lines = (qq{foo\n}, qq{bar\n}); print qq{[[@lines]]}; ;; for $1 (@lines) { chomp $1; print qq{'$1'}; } ;; print qq{[[@lines]]}; " [[foo bar ]] 'foo' 'bar' [[foo bar]]
Everything you would expect to happen to  @lines does happen. Similar code that does not alias  $1 still causes the compiler to barf as expected:
c:\@Work\Perl>perl -wMstrict -le "my @lines = (qq{foo\n}, qq{bar\n}); ;; for my $ln (@lines) { $1 = $ln; chomp $1; print qq{'$1'}; } " Modification of a read-only value attempted at -e line 1.
So I guess I have to say I'm happy with things as they are. (Update: Some men see things as they are and say "Well... Ok, then!")

Update: See "alias" in perlglossary.


Give a man a fish:  <%-(-(-(-<


In reply to Re^4: Getting an unknown error by AnomalousMonk
in thread Getting an unknown error by andybshaker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.