# New Ticket Created by awwa...@thelackthereof.org # Please include the string: [perl #127749] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=127749 >
Here is an example that works as expected: > for ^2 { my $n = 5; say [+] (^$n X ^$n) } 50 50 If we use constants to construct the Seq, it is not re-created on the second loop iteration: > for ^2 { say [+] (^5 X ^5) } 50 This Seq has already been iterated, and its values consumed (you might solve this by adding .cache on usages of the Seq, or by assigning the Seq into an array) in block <unit> at <unknown file> line 1 In my particular case after building the Seq I was applying map and grep to it which would change on each iteration -- it yells at me for the constant-Seq re-use even though I am doing different things with it each time. > for ^2 -> $n { say [+] (^5 X ^5).map(* + $n) } 50 This Seq has already been iterated, and its values consumed (you might solve this by adding .cache on usages of the Seq, or by assigning the Seq into an array) in block <unit> at <unknown file> line 1 I don't feel that the suggested .cache is appropriate, but maybe I'm wrong? Seems like if I wanted this Seq to be shared I should have to define it before the block. Note that if I manually unrolled this loop I wouldn't get the error (since the Seq would be written out twice, so not considered the same Seq).