Hi Monks!,
I have the following subroutine:
my $DEBUG_FILE = "log"; # Global sub debug { my ($t) = @_; return 0 unless(defined($DEBUG_FILE)); open my $fh, ">>",$DEBUG_FILE or return 0; my $prefix = "[".get_date()."][".basename($0)."](".$$."):"; print $fh $prefix.$t."\n"; close ($fh); return 1; }
This subroutine gets a string and logs it into a debug file. This file is for the user to see the progress/errors of using my tool.
I have a few steps in the tool and each one (**could**) take some time. For example, one of the steps, takes an array of paths @paths and do some operation on each path. The operation takes some time so the whole step is long. I want to notify the user of the progress of this step.
In my head I have the following idea: Update the latest line of the debug file with the progress bar. The progress bar would look something like:
[07/10/21 17:56:57][run.pl](211653):<some info example1> [07/10/21 17:57:57][run.pl](211653):<some info example2> [07/10/21 17:58:57][run.pl](211653):<some info example3> [07/10/21 17:59:57][run.pl](211653):Running operation <operation>. Pro +gress: 57%.
Then it will update it to be:
[07/10/21 17:56:57][run.pl](211653):<some info example1> [07/10/21 17:57:57][run.pl](211653):<some info example2> [07/10/21 17:58:57][run.pl](211653):<some info example3> [07/10/21 18:05:57][run.pl](211653):Running operation <operation>. Pro +gress: 58%.
Note that it won't add a new line, it will update the old line.
Also the progress percentage is calculated with 100*$handled_paths/$paths_amount where $paths_amount=scalar(@paths) and $handled_paths is the current handled path.
I think that I could just go to the debug file, and just update the latest line each time - but is it the recommended way to do this?

In reply to Recommended way to display progress by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.