in reply to how to speed up program dealing with large numbers?
1) What version of perl are you using?
2) As far as I can tell, this isn't really done much in perl:
my $value = 0; my $range = 0; my $phiApprox = 0; my $i = 0; my $temp = 0; my $fibValue1 = 0; my $fibValue2 = 0;
Declare your variables at (or near) first use, for example:
chomp(my $value = <>); chomp(my $temp = <>); my $range = $value + $temp; my $total; for (0 .. $range) { my $fibValue1 = fib($i); my $fibValue2 = fib($i - 1); ... ... $total++; }
Redeclaring variables inside loops is done with alacrity in perl.
3) Note that you can do this in perl:
use strict; use warnings; use 5.010; my $total; $total++; say $total; --output:-- 1
...which would not work in those other languages you know. Yet, paradoxically you will get a warning if you do this:
use strict; use warnings; use 5.010; my $total; my $result = $total + 1; say $result; --output:-- Use of uninitialized value $total in addition (+) at 1perl.pl line 9. 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to speed up program dealing with large numbers?
by Solarplight (Sexton) on Mar 22, 2010 at 04:25 UTC | |
by GrandFather (Saint) on Mar 22, 2010 at 04:44 UTC | |
by Solarplight (Sexton) on Mar 22, 2010 at 05:09 UTC | |
by GrandFather (Saint) on Mar 22, 2010 at 09:09 UTC | |
by Solarplight (Sexton) on Mar 22, 2010 at 15:27 UTC | |
by 7stud (Deacon) on Mar 22, 2010 at 07:48 UTC | |
by ssandv (Hermit) on Mar 22, 2010 at 21:47 UTC |