in reply to Printing to stdout an array of strings and scalar references
I agree with advice that a template is a good idea, even with a command line tool, but there is already a nice progress package specifically for command line tools: Time::Progress.
#!/usr/bin/env perl use strictures; use Time::Progress; use Time::HiRes "usleep"; # <- just for demo. my $total = 42; my $progress = Time::Progress->new(); $progress->attr( min => 1, max => $total ); $| = 1; for my $done ( 1 .. $total ) { usleep( rand 500_000 ); print $progress->report("\rProcessing: $total files to process %L +%40B%E %p", $done); } print "\nDone!\n";
Update: fixed code booger; s/42/\$total/ in for loop.
|
|---|