Your code, as posted, works just fine for me. If you want, you could list assign the results from the coefficients method. Might make things a bit more self-documenting:
use strict; use warnings; use Statistics::LineFit; my $fit = Statistics::LineFit->new; $fit->setData( [qw[ 1 2 3 4 5 6 7]], [qw[ 2 3 4 5.5 6.5 7.5 8.5]], ) or die; my ($intercept, $slope) = $fit->coefficients; printf "i=%.4f, s=%.4f, R2=%.4f\n", $intercept, $slope, $fit->rSquare +d; # or return ($fit->coefficients, $fit->rSquared);
Maybe you're calling your function that does this stuff in scalar context, and thus flattening the return list? What exactly are you getting back?
• another intruder with the mooring in the heart of the Perl
In reply to Re: Returning Statistics::LineFit variables from a sub
by grinder
in thread Returning Statistics::LineFit variables from a sub
by Win
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |