Hi all:
I translated a program from c to perl.but the perl program cost 15 seconds
compare to the original c one cost only less than 1 second, I guess this
might be the result of I literally translated the program, using a lot of
array subscripts. After I profile the perl program, it turned out my guess
was true.
for($i = 0; $i < @lines; $i++)
{
$sum += $lines[$_]->{foo_value} for ($i - $n + 1 .. $i);
}
sorry I can't post the whole code, but the lines above is the big framework,
I also omit all the boundary check. "$sum += $lines[$_]->{foo_value} for ($i
- $n2 + 1 .. $i)" this line consumes all the time.
I got a array, for each element of the array I have to sum up the $n
elements prior to the current one. I know I should use pop push shift
unshift all the perl list operators instead of subscripting, but I just
don't know how, would somebody tell me what is the perl way of doing this?