in reply to This runs WAY too slow

Here is an example of how the many variables can be replaced with a few arrays in the datafilla sub
sub datafilla { for my $y (1..5){ my $y_diff = ($f_mpy[$y] - $f_mpy[$y-1]) || 1; my $e_diff = ($f_mpe[$y] - $f_mpe[$y-1]); $popbyyer[$y] = $e_diff / $y_diff; $grand[$y] = $grand[$y-1] + ( ($e_diff<0) ? abs ($e_diff) : 0 ); } }
and a test page to check it works as expected
#!/usr/bin/perl use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; our $VERSION = 3.11; #INPUTS form values my $q = CGI->new(); my $f_copyerr = $q->param('copyerr'); my $f_model = $q->param('model'); my $f_initial = $q->param('initial'); my @f_mpy=(); # year my @f_mpe=(); # estimate foreach (0..5){ $f_mpe[$_] = $q->param('mpe'.$_) || 0; $f_mpy[$_] = $q->param('mpy'.$_) || 1; } $f_mpy[0]=0; # CALCS my @grand=(0); my @popbyyer=($f_mpe[0]); datafilla(); my $gener = (reverse sort @f_mpy)[0]; my $total = (reverse sort @f_mpe)[0] + $grand[5] - 1; # RESULTS my $results = results(); # print page print "Content-type: text/html\n\n"; print qq(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head><meta http-equiv='Content-Type' content='text/html; charset=iso- +8859-1' /> <meta http-equiv='Content-Style-Type' content='text/css' /> <style type='text/css'> td {padding: .5em; min-width:2.5em; } </style> <title>Model $f_model</title> </head> <body> $results <p>Program Ver: $VERSION</p </body> </html>); # datafilla sub datafilla { for my $y (1..5){ my $y_diff = ($f_mpy[$y] - $f_mpy[$y-1]) || 1; my $e_diff = ($f_mpe[$y] - $f_mpe[$y-1]); $popbyyer[$y] = $e_diff / $y_diff; $grand[$y] = $grand[$y-1] + ( ($e_diff<0) ? abs ($e_diff) : 0 ); } } # calculation results sub results { my $html = q{<table border="1"> <tr> <td>ix</td> <td>f_mpy</td> <td>f_mpe</td> <td>popbyyer</td> <td>grand</td> </tr>}; for my $ix (0..5){ $html .= qq{ <tr> <td>$ix</td> <td>$f_mpy[$ix]</td> <td>$f_mpe[$ix]</td> <td>$popbyyer[$ix]</td> <td>$grand[$ix]</td> </tr>}; } $html .= qq{</table> gener = $gener<br/> total = $total<br/>}; return $html; }
poj