AR has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am completely stumped by why these two pieces of code act so differently when I run them. This came from a project euler question 48, if you're interested.
Consider
use strict; use warnings; use bigint; my $answer = 0; for my $i ( 1 .. 999 ) { print "$i: $answer\n"; $answer += $i ** $i; } $answer %= 10 ** 10; print "$answer\n";
versus:
use strict; use warnings; use bigint; my $answer = 0; for ( my $i = 1; $i < 1000; $i++ ) { print "$i: $answer\n"; $answer += $i ** $i; } $answer %= 10 ** 10; print "$answer\n";
The first piece of code assigns inf when $i == 145, but the second piece of code keeps on going. Why is the case?
|
|---|