in reply to Re^2: Performing Mathematical Operation on Specific Column of text File
in thread Performing Mathematical Operation on Specific Column of text File
I'm not clear on everything you're trying to do. But to your main question: how to save the last calculated mean so it can be used after the loop, just make sure you declare the variable outside the loop before it starts, like this:
my $mean; my $total = 0; my $count = 0; for ($j = 2; $j < @tableb; $j++) { # do other calcuations if(this_line_matches()){ $mean = $title/$count; # use $mean from outside the loop } } print $mean; # now contains the last value calculated inside the loop
If you don't actually need to calculate the mean for each loop, you could move that calculation to after the loop and only do it once.
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
|
|---|