in reply to Re: Prime Number Finder
in thread Prime Number Finder

TMTOWTDI :-)
#!/usr/bin/perl s;; ;x; while() { print if (1 x++ $\) !~ m } { $|^(..+)\1+$|^$\$} }

Replies are listed 'Best First'.
Re^3: Prime Number Finder
by lonewolf28 (Beadle) on Feb 16, 2015 at 05:12 UTC

    Can you please explain you code? I'm a noob, honestly i didn't understand your code but it works fine.

      Managed utilize it, but I kinda butchered it. Yeah you can still use Math::Prime::Util.

      But I do not know how exactly it work. It does some magic with the output line separator.

      That if structure is hideous.

      sub primes($end) { open my $FH, '>', \my $output or die "Cannot open filehandle: $!"; $output = ""; $\ = 1; while($\ < $end) { $_ = ""; print $FH $_."\n" if( (1 x++ $\) !~ m/ {$ | ^(..+)\ +1+$ | ^\\\$\\$ }/x ); } close($FH); my @primeNumbers = split("\n", $output); shift @primeNumbers; # a blank element will get through return \@primeNumbers; }