Help!: Error with 'Benchmark' module 
Author Message
 Help!: Error with 'Benchmark' module

Hey all,

Just installed the latest version of Perl on a fresh install of Linux
(extra partition) and am attempting to learn how to use modules and
the like without all the hassles of a work admin...

Anyway I keep getting this error:

Benchmark: timing 10000 iterations of bruteforce, quadratic...
Undefined subroutine &main::forloop called at (eval 3) line 1 (#1)
    (F) The subroutine indicated hasn't been defined, or if it was, it
has
    since been undefined.

Uncaught exception from user code:
        Undefined subroutine &main::forloop called at (eval 3) line 1.
        Benchmark::__ANON__ called at
/usr/lib/perl5/5.8.0/Benchmark.pm line 535
        Benchmark::runloop(10000,'forloop(0, 1)') called at
/usr/lib/perl5/5.8.0/Benchmark.pm line 559      
Benchmark::timeit(10000,'forloop(0, 1)') called at
/usr/lib/perl5/5.8.0/Benchmark.pm line 659
        Benchmark::timethis(10000,'forloop(0, 1)','bruteforce','')
called at /usr/lib/perl5/5.8.0/Benchmark.pm line 709
        Benchmark::timethese(10000,'HASH(0x804c014)') called at
./spacetime.pl line 22

I am pretty sure this is telling me that the 'Benchmark' module is not
installed. How do I tell which modules are actually installed? If I
don't have the 'Benchmark' routine then where do I get it? (The
routines on CPAN seem more specific than the one mentioned in the
'Algorithms with Perl' book I'm working through....

Thanks!

entropy



Fri, 04 Nov 2005 03:56:46 GMT  
 Help!: Error with 'Benchmark' module


Quote:
> Hey all,

> Just installed the latest version of Perl on a fresh install of Linux
> (extra partition) and am attempting to learn how to use modules and
> the like without all the hassles of a work admin...

> Anyway I keep getting this error:

> Benchmark: timing 10000 iterations of bruteforce, quadratic...
> Undefined subroutine &main::forloop called at (eval 3) line 1 (#1)
>     (F) The subroutine indicated hasn't been defined, or if it was, it
> has
>     since been undefined.

> Uncaught exception from user code:
>         Undefined subroutine &main::forloop called at (eval 3) line 1.
>         Benchmark::__ANON__ called at
> /usr/lib/perl5/5.8.0/Benchmark.pm line 535
>         Benchmark::runloop(10000,'forloop(0, 1)') called at
> /usr/lib/perl5/5.8.0/Benchmark.pm line 559
> Benchmark::timeit(10000,'forloop(0, 1)') called at
> /usr/lib/perl5/5.8.0/Benchmark.pm line 659
>         Benchmark::timethis(10000,'forloop(0, 1)','bruteforce','')
> called at /usr/lib/perl5/5.8.0/Benchmark.pm line 709
>         Benchmark::timethese(10000,'HASH(0x804c014)') called at
> ./spacetime.pl line 22

> I am pretty sure this is telling me that the 'Benchmark' module is not
> installed.

I am pretty sure it's not :-)
It's telling you that there's something wrong with the coding of your
script.

Quote:
>How do I tell which modules are actually installed?

This works fine for me (lets me know which, of the specified modules, are
missing):

use strict;
use warnings;



    $_ =~ s/::/\//g;
    eval {require "$_.pm"};

    }
__END__



Fri, 04 Nov 2005 04:18:43 GMT  
 Help!: Error with 'Benchmark' module

Quote:
> Anyway I keep getting this error:

READ the error:

Quote:
> Benchmark: timing 10000 iterations of bruteforce, quadratic...

Benchmark is running these two labelled functions of yours...

Quote:
> Undefined subroutine &main::forloop called at (eval 3) line 1 (#1)

It can't find a subroutine called "forloop".

Quote:
>     (F) The subroutine indicated hasn't been defined, or if it was, it has
>     since been undefined.

More details about why it might not be able to find "forloop".

Quote:
> Uncaught exception from user code:

This is why it died.

Quote:
>         Undefined subroutine &main::forloop called at (eval 3) line 1.

This is where it died.

Quote:
>         Benchmark::__ANON__ called at /usr/lib/perl5/5.8.0/Benchmark.pm line 535
>         Benchmark::runloop(10000,'forloop(0, 1)') called at /usr/lib/perl5/5.8.0/Benchmark.pm line 559      
>         Benchmark::timeit(10000,'forloop(0, 1)') called at /usr/lib/perl5/5.8.0/Benchmark.pm line 659
>         Benchmark::timethis(10000,'forloop(0, 1)','bruteforce','') called at /usr/lib/perl5/5.8.0/Benchmark.pm line 709
>         Benchmark::timethese(10000,'HASH(0x804c014)') called at ./spacetime.pl line 22

This is a callback dump of where your program crashed.  Note that
most of these functions are in the Benchmark module.

Good heavens, you aren't really doing development as root, are you??

Quote:
> I am pretty sure this is telling me that the 'Benchmark' module is not
> installed. How do I tell which modules are actually installed? If I

Unless your program has code that prints out "Benchmark: timing 10000
iterations of..." and has subroutines called Benchmark::runloop,
Benchmark::timeit, Benchmark::timethis, and Benchmark::timethese, I
strongly suspect that you do in fact have the Benchmark module installed.

--
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;



Fri, 04 Nov 2005 10:59:18 GMT  
 Help!: Error with 'Benchmark' module
here is my code, it is straight from the 'Mastering Algorithms with Perl' book....

Appreciate it if you look it over and find my error...

Matt

#!/usr/bin/perl -w

use strict;

use diagnostics;

use Benchmark;

sub quadtratic { #Compute the larger root of a quadtratic polynomial

    return (-$b + sqrt($b*$b -4*$a*$c))/2*$a;

Quote:
}

sub bruteforce {  #Search linearly until we find a good enough choice

    my $x;
    for ($x = $low; $x <= $high; $x += .001) {
        return $x if abs($x * ($x+1)- .999) <  .001;
    }

Quote:
}

timethese(10000, {quadratic  => 'quadratic(1, 1, -1)',
                  bruteforce => 'forloop(0, 1)'         });


Fri, 04 Nov 2005 17:06:57 GMT  
 Help!: Error with 'Benchmark' module

Quote:

> here is my code, it is straight from the 'Mastering Algorithms with Perl'
> book....

> Appreciate it if you look it over and find my error...

Is this a joke?

Quote:
> timethese(10000, {quadratic  => 'quadratic(1, 1, -1)',
>                   bruteforce => 'forloop(0, 1)'         });

                                   ^^^^^^^

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB



Fri, 04 Nov 2005 17:10:37 GMT  
 Help!: Error with 'Benchmark' module

Quote:


> > here is my code, it is straight from the 'Mastering Algorithms with Perl'
> > book....

> > Appreciate it if you look it over and find my error...

> Is this a joke?

> > timethese(10000, {quadratic  => 'quadratic(1, 1, -1)',
> >                   bruteforce => 'forloop(0, 1)'         });
>                                    ^^^^^^^

> Xho

Sadly no joke. I fixed the 'forloop' part, but still the damned thing
did not run. I went to the website and downloaded the code
examples...which did work..
Matt


Sat, 05 Nov 2005 00:08:46 GMT  
 Help!: Error with 'Benchmark' module

Quote:


>>here is my code, it is straight from the 'Mastering Algorithms with Perl'
>>book....

>>Appreciate it if you look it over and find my error...

> Is this a joke?

Sigh.  Probably not.  The OP doesn't realize the hash key is the
arbitrary name and the value is the code to be timed.  So the
"bruteforce" line should go:

                   forloop => 'bruteforce(0, 1)'   });

He also doesn't realize there is a typo in his copy of the code
"straight from ...":  sub quadtratic is defined; sub quadratic is
called.  So as soon as the first error is fixed, the second one, which
looks pertty similar, will appear.

I checked:  the "bruteforce => 'forloop(0, 1)..." error exists in the
book (first edition); the other error does not.  The error was corrected
in the 2000 reprint, and appears in the errata on the O'Reilly web site.

Sigh.

Quote:

>>timethese(10000, {quadratic  => 'quadratic(1, 1, -1)',
>>                  bruteforce => 'forloop(0, 1)'         });

>                                    ^^^^^^^

> Xho

--
Bob Walton


Sat, 05 Nov 2005 01:35:37 GMT  
 Help!: Error with 'Benchmark' module

Quote:



>>>here is my code, it is straight from the 'Mastering Algorithms with Perl'
>>>book....

>>>Appreciate it if you look it over and find my error...

>>Is this a joke?

>>>timethese(10000, {quadratic  => 'quadratic(1, 1, -1)',
>>>                  bruteforce => 'forloop(0, 1)'         });

>>                                   ^^^^^^^

>>Xho

> Sadly no joke. I fixed the 'forloop' part, but still the damned thing
> did not run. I went to the website and downloaded the code
> examples...which did work..
> Matt

In addition to that, you misspelled the name of sub quadratic as sub
quadtratic when you defined the sub.  Fix that also and see if it works.
--
Bob Walton


Sat, 05 Nov 2005 01:41:58 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. make error loading module via 'cpan'

2. CGI Scripting Errors 'Help'

3. help with 'internal server error'?

4. Theoretical 'Help Button' Module

5. Can't Find Benchmark on CPAN

6. Can't install Net module using ppm - Can't find module

7. Can't find loadable object for module Win32::ODBC error

8. Error: Can't load .../foo.o for module bar

9. Can't load IO.so error when trying to install CPAN modules

10. DB_File module error msg's in conjunction with netscape-history3.00

11. Module loading error: Apache can't load Apache::Server

12. Error: can't locate loadable module

 

 
Powered by phpBB® Forum Software