in reply to does a hash element as a loop parameter cause significant slowdown?

for my $c (1..$n1) {

The list 1..$n1 is created in memory and then iterated over so $n1 is only evaluated once.

If you instead used a C style for loop then $n1 would be evaluated $n1 times.

Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
  • Comment on Re: does a hash element as a loop parameter cause significant slowdown?
  • Download Code

Replies are listed 'Best First'.
Re^2: does a hash element as a loop parameter cause significant slowdown?
by LanX (Saint) on Sep 08, 2023 at 23:34 UTC
      Maybe 5.10ish?

      I checked perldoc.perl.org's 5.10 docs: it still had the "but older versions" comment.

      So I checked 5.005's docs: it still had the "but older versions" comment.

      So if perldoc.perl.org's copies of the docs are accurate, it was documenting the list-in-memory behavior as "old" even at 5.005!

      /me guesses he needs to get over his aversion to large ranges in foreach loops ;-)