in reply to overwrite last line printed
Try logging progress to both default output (STDOUT) and global filehandle LOG with LOGress :)
BEGIN { my $started = !!0; sub LOGress { my $string = join '', @_; my $before = tell select; print $string; my $after = tell select; if( $started ){ seek LOG -abs( $after - $before ), 2; # rewind } print LOG $string; if( 0 <= index $string, "\n" ){ $started = !!0; } else { $started = !!1; } } } ... LOGress "\rProgress...$x\%"; ... LOGress "\rProgress...Done!\n"; # \n signals end
use autodie qw/ open close seek tell /; to die if those calls fail
|
|---|