1

I'm trying to make a simple text-based progress bar in perl, in order to display the progress while sending an email or doing a task.

Any pointers ?! Thanks

amrfaissal
  • 1,060
  • 1
  • 7
  • 18

3 Answers3

4

Damian Conway's Smart::Comments module includes text progress bars.

daxim
  • 39,270
  • 4
  • 65
  • 132
Bill Ruppert
  • 8,956
  • 7
  • 27
  • 44
  • 1
    Smart::Comments can be enabled or disabled at runtime too: [module](http://search.cpan.org/~chorny/Smart-Comments-1.0.4/lib/Smart/Comments.pm#CONFIGURATION_AND_ENVIRONMENT) – JRFerguson Nov 07 '11 at 13:30
3

I’m quite fond of Time::Progress for terminal stuff. Simplistic example–

use warnings;
use strict;
use Time::Progress;
use Time::HiRes "usleep"; # for demo.

my $timer = Time::Progress->new();
my $some_total_to_reach = 10_000;
$timer->attr( min => 1, max => $some_total_to_reach );

my $count = 1;
while ( $some_total_to_reach-- )
{
    print $timer->report("Doing stuff: %40b%p%L%E\r", $count++);
    usleep int(rand(1_000));
}

print "\nDone!\n";
Ashley
  • 4,307
  • 2
  • 19
  • 28
  • the problem is i need to feed the progress bar while i'm sending a mail. When i finish sending the progress bar must finish too ! – amrfaissal Nov 07 '11 at 03:30
  • 1
    How are you sending the mail? Are you using Net::SMTP with datasend? Are you sending one line at a time? Do you know how many lines you are sending to start with? – Bill Ruppert Nov 07 '11 at 04:45
1

I used Term::ProgressBar module, and after each done operation i call update() method. That's all. Thank you all, especially Bill Ruppert ;)

amrfaissal
  • 1,060
  • 1
  • 7
  • 18