There's more than one way to do things PerlMonks

### Comment on

 Need Help??
Much worse than the previous offering and just plain bad approaches (what can I say--I'm bad at golf and I wanted to play with using an array. look here if you want to see some shorter solutions):

```# Example use: @result = sieve(60);
sub sieve {
my\$m=pop;my@l=(0..\$m);for(my\$x=0;\$x<\$m;\$x++){next if(\$l[\$x]<2);my \$i=2
+;my\$n=0;for(;\$n<\$m;\$i++){\$n=\$x*\$i;next if(\$n>\$m);\$l[\$
n]=0}}@l=grep{\$l[\$_]}(0..\$m)
}
152.

```# Example of use: sieve(60);

sub sieve {
my\$m=pop;@_=(2..\$m);for my \$c(@_){my%b=map{\$_,1}grep{(\$_%\$c)==0}(\$c+1.
+.\$m);@_=grep{!\$b{\$_}}@_}die"@_\n"
}
104.

Update

```# Example of use: @result = sieve(60);

sub sieve{
L:for(2..pop){for my \$b(2..\$_-1){next L if(\$_%\$b<1)}push@_,\$_}@_
}

65. Does not mark of multiples but tests each number (only as far as needed, at least), so not really allowed.

In reply to (kudra: basketball) Re: (Golf): Sieve of Eratosthenes by kudra
in thread (Golf): Sieve of Eratosthenes by tilly

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.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-01-23 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (238 votes). Check out past polls.

Notices?