Hi,
I made a perl mod called regression that takes a pointer to a hash of x,y data pairs when it is blessed. I tested it with a simple program and verified that it runs with that program. Here is part of the simple program code…
my %raw_data = (
1 => 100,
2 => 160,
2.5 => 182,
3 => 225
);
my $regr = regression->new(\%raw_data);
print '$regr= ', Dumper($regr);
$mean_x = $regr->get_mean_x;
print '$mean_x= ', Dumper($mean_x);
and here is some of the output. (The numbers are all correct.)
$regr= $VAR1 = bless( {
'mean_y' => '166.75',
'raw_data' => {
'1' => 100,
'3' => 225,
'2' => 160,
'2.5' => 182
},
'slope' => '60.6285714285714',
'mean_x' => '2.125',
'y_intercept' => '37.9142857142857'
}, 'regression' );
Well, I try it with a work example, which requires a more complicated hash structure.
Here is where the hash is populated:
$raw_dataPtr = \%{$element_stats_hash{$element_name}{'raw_data
+'}};
$$raw_dataPtr{$time} = {$var};
So, the hash key is set to the values in variable $time and the hash value is set to values in variable $var.
Here is where the object is blessed into existence:
#$regr = regression->new(\%{$element_stats_hash{$element_name}{'ra
+w_data'}});
$regr = regression->new(\%{$element_stats_hash{$element_name}});
print TEST '$regr= ', Dumper($regr);
I have also tried this:
$regr = regression->new(\%{$element_stats_hash{$element_name}});
print TEST '$regr= ', Dumper($regr);
Here is the output of the class’s hash data structure (either way):
'raw_data' => {
'1229265435' => {
'0.
+12205589' => undef
},
'1229299036' => {
'0.
+71940041' => undef
},
'1229317107' => {
'1.
+22392523' => undef
},
Of course, I WANT it to look like this:
'raw_data' => {
'1229265435' => '0.12
+205589',
'1229299036' => '0.71
+940041',
'1229317107' => '1.2239252
+3'
},
and I just cannot seem to understand what is going on here. Might someone be able to explain to me what I need to do in order to get the hash in the class to look like I want it to? And can someone explain what is presently going on?
Many thanks in advance.
Tony
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.