http://qs321.pair.com?node_id=1231622

pgmer6809 has asked for the wisdom of the Perl Monks concerning the following question:

On Rosetta (https://rosettacode.org/wiki/Continued_fraction#Perl )

there is the perl solution to evaluating Continuous fractions. The code given is: (<===== comments added by me)

sub continued_fraction { my ($a, $b, $n) = (@_[0,1], $_[2] // 100); #<========= what is $_[2] // 100 ?? $a->() + ($n && $b->() / continued_fraction($a, $b, $n-1)); } printf "&#8730;2 &#8776; %.9f\n", continued_fraction do { my $n; sub +{ $n++ ? 2 : 1 } }, sub { 1 }; # <===== Note there is no third arg p +assed printf "e &#8776; %.9f\n", continued_fraction do { my $n; sub { $n++ + || 2 } }, do { my $n; sub { $n++ || 1 } }; # <===== Note there is no + third arg passed printf "&#960; &#8776; %.9f\n", continued_fraction do { my $n; sub { + $n++ ? 6 : 3 } }, do { my $n; sub { (2*$n++ + 1)**2 } }, 1_000; #<== +== Here there is a 3rd arg printf "&#960;/2 &#8776; %.9f\n", continued_fraction do { my $n; sub { + 1/($n++ || 1) } }, sub { 1 }, 1_000; #<==== Here there is a 3rd arg

The output shown on Rosetta is correct

.

My TWO questions are:

1) Why can they pass in two arguments sometimes (two function refs) and three arguments other times (two function refs, and an integer count?

2) What value does the expression $_[2] // 100 assign to $n ?