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;
}
|