Horner's rule for polynomial evaluation: Difference between revisions

→‎{{header|Perl}}: might as well use the convenience of prototype; not popping a ref is generally more practical
(→‎{{header|Perl}}: might as well use the convenience of prototype; not popping a ref is generally more practical)
Line 645:
 
=={{header|Perl}}==
<lang Perl>use feature ':5.10'.0;
use strict;
use warnings;
}
 
sub horner($\@$){
my ($coeff_refcoef, $x) = @_;
my $result = 0;
$result = $result * $x + pop$_ for reverse @$coeff_refcoef;
while(@$coeff_ref){
$result = $result * $x + pop @$coeff_ref;
}
return $result;
}
 
my @coeff = (-19.0, 7, -4, 6);
my $x = 3;
say horner(\ @coeff, $x);</lang>
 
===Functional version===
Anonymous user