in reply to A specific term for a Perlism

"...and modifying the iterator variable modifies the array that you are iterating through ..."

foreach my $a (@ar) ...

You are not using the "traditional" C style for loop. You are using the Perl style foreach loop. From perlsyn:

The "foreach" loop iterates over a normal list value and sets the scalar variable VAR to be each element of the list in turn.

Big difference. You might be comparing apples to oranges here. 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; } print join ", ", @ar; # prints 1, 2, 3
See the difference?

UPDATE:
I was attempting to point out that the OP mentioned "modifying the iterator variable" when they are actually modifying the "loop index variable" as perlsyn documents.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: A specific term for a Perlism
by AnomalousMonk (Archbishop) on Mar 19, 2015 at 19:47 UTC
    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:  <%-(-(-(-<

Re^2: A specific term for a Perlism
by Anonymous Monk on Mar 19, 2015 at 18:16 UTC

    He didn't say he was using a C-style for loop, did he?

    Might you be trying to answer a question that no one asked?