1Term::ProgressBar::SimpUlsee(r3)Contributed Perl DocumenTteartmi:o:nProgressBar::Simple(3)
2
3
4

NAME

6       Term::ProgressBar::Simple - simpler progress bars
7

SYNOPSIS

9           # create some things to loop over
10           my @things = (...);
11           my $number_of_things = scalar @things;
12
13           # create the progress bar object
14           my $progress = Term::ProgressBar::Simple->new( $number_of_things );
15
16           # loop
17           foreach my $thing (@things) {
18
19               # do some work
20               $thing->do_something();
21
22               # increment the progress bar object to tell it a step has been taken.
23               $progress++;
24           }
25
26           # See also use of '$progress += $number' later in pod
27

DESCRIPTION

29       Progress bars are handy - they tell you how much work has been done,
30       how much is left to do and estimate how long it will take.
31
32       But they can be fiddly!
33
34       This module does the right thing in almost all cases in a really
35       convenient way.
36

FEATURES

38       Lots - does all the best practice:
39
40       Wraps Term::ProgressBar::Quiet so there is no output unless the code is
41       running interactively - lets you put them in cron scripts.
42
43       Deals with minor updates - only refreshes the screen when it will
44       change what the user sees so it is efficient.
45
46       Completes the progress bar when the progress object is destroyed
47       (explicitly or by going out of scope) - no more '99%' done.
48

METHODS

50   new
51           # Either...
52           my $progress = Term::ProgressBar::Simple->new($count);
53
54           # ... or
55           my $progress = Term::ProgressBar::Simple->new(
56               {
57                   count => $count,               #
58                   name  => 'descriptive text',
59               }
60           );
61
62       Create a new progress bar. Either just pass in the number of things to
63       do, or a config hash. See Term::ProgressBar for details.
64
65   increment ( ++ )
66           $progress++;
67
68       Incrementing the object causes the progress display to be updated. It
69       is smart about checking to see if the display needs to be updated.
70
71   increment ( += )
72           $progress += $number_done;
73
74       Sometimes you'll have done more than one step between updates. A good
75       example is processing logfiles, where the time taken is relative to the
76       size of the file.  In this case code like this would give a better feel
77       for the progress made:
78
79           # Get the total size of all the files
80           my $total_size = sum map { -s } @filenames;
81
82           # Set up object with total size as steps to do
83           my $progress = Term::ProgressBar::Simple->new($total_size);
84
85           # process each file and increment by the size of each file
86           foreach my $filename (@filenames) {
87               process_the_file($filename);
88               $progress += -s $filename;
89           }
90
91   message
92           $progress->message('Copying $filename');
93
94       Output a message. This is very much like print, but we try not to
95       disturb the terminal.
96

SEE ALSO

98       Term::ProgressBar & Term::ProgressBar::Quiet
99

GOTCHAS

101       Not all operators are overloaded, so things might blow up in
102       interesting ways.  Patches welcome.
103

THANKS

105       Martyn J. Pearce for the orginal and great Term::ProgressBar.
106
107       Leon Brocard for doing the hard work in Term::ProgressBar::Quiet, and
108       for submitting a patch with the code for "+="..
109
110       YAPC::EU::2008 for providing the venue and coffee whilst the first
111       version of this module was written.
112

AUTHOR

114       Edmund von der Burg "<evdb@ecclestoad.co.uk>".
115
116       <http://www.ecclestoad.co.uk/>
117

BUGS

119       There are no tests - there should be. The smart way would be to trap
120       the output and check it is right.
121
123       Copyright (c) 2008, Edmund von der Burg "<evdb@ecclestoad.co.uk>".  All
124       rights reserved.
125
126       This module is free software; you can redistribute it and/or modify it
127       under the same terms as Perl itself.
128
129
130
131perl v5.36.0                      2023-01-20      Term::ProgressBar::Simple(3)
Impressum