in reply to perls long number problem
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.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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: perls long number problem
by tilly (Archbishop) on Dec 15, 2001 at 06:02 UTC |