Hi, I've been running the following code below and get the following errors:
#!/usr/bin/env perl
use warnings;
use strict;
use ntheory;
use bigint;
my $n=12;
my $c=1;
my $k=10;
my $l=10;
my $p=100;
my @candidates = (0..$l);
my $remove;
sieve2();
sub sieve2 {
forprimes { $p=$_;
foreach my $i (0..$l) {
if ( ($n*($k+$i)+$c)%$p==0)
{
$remove=$i;
@candidates = grep {!/$remove/} @candidates;
}
}
}
print join("\n",@candidates),"\n";
}
sieve2();
Errors:
C:\Users\Perl Scripts> sieve2.pl
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
Use of uninitialized value in new at C:\Users\Paul\Documents\Perl Scri
+pts\question.pl line 20.
0
1
2
3
4
5
6
7
8
9
10
Can't call method "forprimes" without a package or object reference at
+ C:\Users\Paul\Documents\Perl Scripts\question.pl line 18.
So I know that I've included the right dependencies for forprimes (the exact function is right here: https://metacpan.org/pod/ntheory#forprimes) so I don't see what I'm doing wrong. To be more specific about the code:
Given integers n, c, k, l, and p, sieves all numbers of the form n*(k+i)+c where 0 <= i <= l up to all primes less than p. So in my program example where I chose parameters 12, 1, 10, 10, and 100 respectively, the correct output should be:
3
5
6
9
10
Any ideas of how to obtain this? Thanks for help in advance!