Skip to content

Instantly share code, notes, and snippets.

@ology
Created May 20, 2023 07:39
Show Gist options
  • Save ology/2d4868bb10589d532a061375fb48acad to your computer and use it in GitHub Desktop.
Save ology/2d4868bb10589d532a061375fb48acad to your computer and use it in GitHub Desktop.
require Some::Module in a single function
sub cfsqrt {
my ($self, $n, $m) = @_;
$m ||= $n;
my @terms;
my $ok = eval {
require Math::NumSeq::SqrtContinued;
1;
};
die 'ERROR: Math::NumSeq::SqrtContinued not installed'
unless $ok;
my $seq = Math::NumSeq::SqrtContinued->new(sqrt => $n);
for my $i (1 .. $m) {
my ($j, $value) = $seq->next;
push @terms, $value;
}
return \@terms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment