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!

In reply to Can't call method "forprimes" by pvfki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.