CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Time in seconds



Nov 3, 2009, 6:46 AM

Post #1 of 4 (2506 views)
Time in seconds Can't Post

Hi all

i have a perl script that print out all prime numbers up to a chosen integer but i need a way to find out how long it took to run

i have used the "print time - $^T;" option but this only does seconds, is there a way so it can do more than just seconds , say micro seconds, below is my code

use strict ;
my @list = 1..10000;
foreach $a (@list) {
foreach $b(@list) {
if ((int($a/$b)==($a/$b))) {
push @total, $b;
print "$a is prime\n" if ($#total == 1);

print time - $^T;

Veteran / Moderator

Nov 3, 2009, 6:49 AM

Post #2 of 4 (2505 views)
Re: [ab] Time in seconds [In reply to] Can't Post



Nov 3, 2009, 6:55 AM

Post #3 of 4 (2502 views)
Re: [FishMonger] Time in seconds [In reply to] Can't Post

sorry i am sure i am being a complete numpty but how was i used that with my code


Veteran / Moderator

Nov 3, 2009, 7:19 AM

Post #4 of 4 (2499 views)
Re: [ab] Time in seconds [In reply to] Can't Post

First, don't use $a or $b. Those are 2 of Perl's special built-in global vars that are used in the sort function.

Var names should describe (or give a hint) what data the var holds.

Have you read the documentation for the module? It provides several examples of its usage.

This is clearly a homework assignment, so I can't/won't provide the complete solution. But, if you give it a try and get stuck, post the updated code that you're testing with a specific question on the part that you can't figure out, I'll give you a little more guidance.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives