in reply to Re: A specific term for a Perlism
in thread A specific term for a Perlism

Consider this code which actually changes the iterator variable instead of the element.

my @ar = (1, 2, 3);
for my $i (0 .. $#ar) {
  $i = $i + 1;
}

I understand you to be saying that in the quoted code, a change to $i does not affect the loop list element from which the value of $i is drawn, i.e, $i is not an alias.

But consider the failure of the following:

c:\@Work\Perl\monks>perl -wMstrict -le "print 'runtime'; for my $i (1, 2, 3) { $i = $i + 1; print $i; } print 'done'; " runtime Modification of a read-only value attempted at -e line 1.

I think that in both cases $i is being aliased to elements of an anonymous loop list.

In the first (quoted) case, the  (0 .. $#ar) expression creates a mutable anonymous list, the elements of which can be changed freely.

In the second case,  (1, 2, 3) creates an immutable loop list. In this case, the statement
    $i = $i + 1;
is equivalent to the meaningless statement
    1 = 1 + 1;
for the first element of the loop list because $i is aliased to a literal 1, and the interpreter throws up its hands.


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