Skip to content

Commit

Permalink
Remove caveat about temporary arrays in for range loops
Browse files Browse the repository at this point in the history
The optimisation to not create the array was introduced in Perl
5.005 (commit 89ea290), there's no
need to have a caveat about versions older than that any more.
  • Loading branch information
ilmari committed Nov 27, 2024
1 parent 80f266d commit aaee595
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions pod/perlop.pod
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,9 @@ operators depending on the context. In list context, it returns a
list of values counting (up by ones) from the left value to the right
value. If the left value is greater than the right value then it
returns the empty list. The range operator is useful for writing
S<C<foreach (1..10)>> loops and for doing slice operations on arrays. In
the current implementation, no temporary array is created when the
range operator is used as the expression in C<foreach> loops, but older
versions of Perl might burn a lot of memory when you write something
like this:

for (1 .. 1_000_000) {
# code
}
S<C<foreach (1..10)>> loops and for doing slice operations on arrays.
No temporary array is created when the range operator is used as the
expression in C<foreach> loops.

The range operator also works on strings, using the magical
auto-increment, see below.
Expand Down

0 comments on commit aaee595

Please sign in to comment.