If my memory serves me correctly, you have changed the code in the OP (without citation; please see below). The latest code I see in the OP seems very close to what I think you want; it certainly seems closer than what I see above.

If you compile the latest code in the OP you see error messages like
    Global symbol "@prime" requires explicit package name at ...
    Missing right curly or square bracket at ...
(The ... represent line numbers that I do not see because I am compiling from the command line. If you compile from a source file, you should see valid line numbers.) Please address these (fairly minor) errors in the latest code in the OP.

Once you correct these errors, please consider the statement
    my $f = listprimes($a);
This takes the list returned from the  listprimes() call and assigns it to a scalar variable. Is this correct? What would happen if this list was assigned to an array and the array was then printed? If you address this final problem, I think you're done.

Finally, if my memory serves me correctly, you have changed the code in the OP without citation! Please don't do that; it makes every reply that refers to the original Original Post inconsistent and incoherent. Please see How do I change/delete my post? for the proper etiquette for making changes to your posts. The basic commandment is this: Do Not Destroy Context.

Also: don't use  $a $b for lexical variable names; they are Perl special variables (see perlvar) and have special uses.


Give a man a fish:  <%-{-{-{-<


In reply to Re^5: Perl program - I hope I can more understand my code by AnomalousMonk
in thread Perl program - I hope I can more understand my code by brianphan

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.