in reply to perls long number problem

I have not had problems with Perl handling large numbers. I had written a program for multiplying very large prime numbers together (a bit of cracking). The results were up to 12 digits long.
open (FILE, 'pout.txt') || die "Could not open output:\n $!\n"; $i = 0; while (<FILE>){ chomp($_); ($key, $prime) =split (/ /, $_); push (@prime, $prime); } $nop = @prime; print "$nop primes found.\n"; $i = 0; until ( $i == 1) { print "Enter First Key\: "; $key1 = <STDIN>; chomp ($key1); print "Enter Second Key\: "; $key2 = <STDIN>; chomp ($key2); $total = (@prime[$key1] * @prime[$key2]); print "@prime[$key1] times @prime[$key2] is $total\n"; }
This code takes my file with a key ordered list of prime numbers and pushes each prime onto @prime. It then asks the user to specify to keys to multiply together and prints the result. I was about to handle some very large numbers with this.

Sparky

Replies are listed 'Best First'.
Re (tilly) 2: perls long number problem
by tilly (Archbishop) on Dec 15, 2001 at 06:02 UTC
    If you turned on warnings you would get several warnings about that code. (In particular centered about the fact that you don't know how to correctly access an element of an array.)

    Also note that 12 digits, your preconceptions notwithstanding, is not a large number. Try 10 times that many digits and see if you don't discover what Perl's large number limits look like...