Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use Modern::Perl;
sub is_prime {
my $n = shift;
$n <= 1 and return;
my $i = 1;
primes :: [Integer]
primes = 2 : filter isPrime [3, 5 ..]
where
-- only check divisibility of the numbers less than the square root of n
isPrime n = all (not . divides n) $ takeWhile (\p -> p*p <= n) primes
divides n p = n `mod` p == 0
result = sum $ takeWhile (< 2000000) primes
main = do putStrLn( show result )
#!/usr/bin/env perl
use Modern::Perl;
use Sub::Call::Recur;
use Sub::Call::Tail;
use Benchmark 'cmpthese';
no warnings 'recursion';
sub fact_recur {
my ($n, $accum) = @_;
coerce BioSimpleAlign,
from BioSeqIO, via { _seq_to_aln( _seqI_to_seq($_) ) },
from BioSeq, via { _seq_to_aln($_) },
from BioAlignIO, via { $_->next_aln },
from ProfileFile, via { _filename_to_aln($_) };
brunov@dora:~$ re.pl
$_ my $thing = Foo->new;
$Foo1 = Foo=HASH(0xa77cb98)
$_ my $other = Bar->new;
$Bar1 = Bar=HASH(0xabc4eb8)
# in ~/.repl/repl.rc:
use Class::Autouse qw(:superloader);
use Class::Autouse qw(:superloader);
my $thing = Dep::2->new;
my @deps; push "Dep::$_" for (1..10);
use Class::Autouse @deps;
my $thing = Dep::2->new;
use Dep::1;
use Dep::2;
...
use Dep::10;
my $thing = Dep::2->new;
#!/usr/bin/perl
use Modern::Perl;
use POE qw(Component::DirWatch::Object::NewFile);
use Bio::SeqIO;
use Bio::Seq;
use File::Temp;
use File::Copy qw(move);
use Gtk2::Notify -init, "Translator";
my $watcher = POE::Component::DirWatch::Object::NewFile->new(