in reply to Recommended way to display progress

The operation takes some time so the whole step is long. I want to notify the user of the progress of this step.

What is the user looking at? Is he or she looking at a terminal which is displaying some sort of tail of the log file?

A better approach might be to just directly output to the terminal something like:

my $max_width = ...; # longest possible progress message text my $percent_done = int(100*$handled_paths/@paths); my $progress = build_user_handhold_message(..., ..., $percent_done); printf "\r%-*s", $max_width, $progress;
Of course, the latter three lines have to be done in some kind of loop while the process is... well, in process. (Update: And you'd better set $| (autoflush; see perlvar) true within the loop so something will actually print without newlines.)

The \r in the printf format string is a carriage return: it returns the cursor to the start of the terminal line without doing a newline. The %-*s left-justifies the $progress text in a field of spaces $max_width wide (due to the * "next argument" specifier). IOW, you get a single line that refreshes over and over with updated progress and percent-done info.


Give a man a fish:  <%-{-{-{-<