Almost similar, but I am looking for functionality where I can call and mesure the progress for the routine as it is executed. So the line 'print progress_bar' should be outside the 'foo' here. I should have independent way of measuring the progress of the subroutine. I guess the only way to achive that is to implement the call back routines or implement threads .
Doesn't display anything for the longuest time because STDOUT is not being flushed. Setting STDOUT to outflush or adding a call to flush (defined below) after the print does the trick.
sub flush {
my $h = select($_[0]); my $a=$|; $|=1; $|=$a; select($h);
}