A similar problem is addressed in Higher order Perl. (Chapter 1, page 35)
citromatik
In reply to Re^2: Average Price Algorithm by citromatik in thread Average Price Algorithm by camelcom