1

I'm trying to generate random prime number

print Math::Prime::Util->random_strong_prime(128);

But, when I call one of the methods (i tried various) of Math::Prime::Util, I get:

Parameter 'Math::Prime::Util' must be a positive integer at /home/ivan/perl5/lib/perl5/x86_64-linux-thread-multi/Math/Prime/Util.pm line 400.

I can't understend what's wrong, 128 is positive and integer. Script runs under Starman server(psgi)

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Ivan
  • 325
  • 3
  • 9

1 Answers1

6

When you use the method invocation syntax, i.e.,

Math::Prime::Util->random_strong_prime(128);

the first argument to random_strong_prime becomes the string "Math::Prime::Util" which is not a positive integer. With method invocation syntax, 128 becomes the second parameter.

The syntax you are using is appropriate for invoking a class method.

Instead, you want to use function invocation syntax:

print Math::Prime::Util::random_strong_prime(128);

You can verify this using the following simple program:

#!/usr/bin/env perl

package Hello;

sub f { print "@_\n" }

package main;

Hello->f('world');
Hello::f('world');
$ ./gg.pl
Hello world
world
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339