o2bwise has asked for the wisdom of the Perl Monks concerning the following question:
package regression; use strict; sub new { my ($class) = @_; bless { 'raw_data' => $_[1], 'mean_x' => 0, 'mean_y' => 0, 'slope' => 0, 'y_intercept' => 0 }, $class; } sub get_mean_x { $raw_dataPtr = $_[0]{'raw_data'}; my $counter = 1; my $x_total = 0; print "raw_datePtr: $raw_datePtr\n"; foreach $x (keys %$raw_dataPtr) { ++$counter; $x_total += $x; } my $mean_x = ($x_total/$counter); $self->{'mean_x'} = $mean_x; return ($self->{'mean_x'}); }
#!/usr/bin/perl -w use strict; require ('/opt/eHealth/web/aview/perl/site/lib/regression.pm'); open (TEST,">testing.txt"); my ($mean_x,$mean_y,$slope,$y_intercept); my %raw_data = ( 1 => 100, 2 => 160, 2.5 => 182, 3 => 225 ); my $regr = regression->new(\%raw_data); $mean_x = $regr->get_mean_x; #$mean_y = $regr->get_mean_y; #$slope = $regr->get_slope; #$y_intercept = $regr->get_slope; print TEST "Mean_x: $mean_x\tMean_y: $mean_y\tSlope: $slope\t: y inter +cept: $y_intercept\n"; close (TEST);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: basic OOP question
by lostjimmy (Chaplain) on Nov 13, 2008 at 21:02 UTC | |
|
Re: basic OOP question
by ig (Vicar) on Nov 13, 2008 at 21:11 UTC | |
|
Re: basic OOP question
by Anonymous Monk on Nov 13, 2008 at 21:05 UTC | |
|
Re: basic OOP question
by fmerges (Chaplain) on Nov 14, 2008 at 05:21 UTC |