]> git.donarmstrong.com Git - don.git/blob - posts/using_term_progressbar.mdwn
add Term::ProgressBar entry
[don.git] / posts / using_term_progressbar.mdwn
1 [[!meta title="Using Term::Progressbar"]] 
2
3 I've been working for a while on analyzing a fairly large dataset for
4 my Lupus genetics project. One of the major annoyances with analyzing
5 large datasets is not knowing when a particular part of the analysis
6 is going to finish, and whether I should go back and rewrite part of
7 the code to be faster, or just wait for it to finish. In R, I've been
8 using txtProgressBar to handle this, but I hadn't bothered to find a
9 similar module for perl until now.
10
11 Luckily,
12 [Term::ProgressBar](http://search.cpan.org/dist/Term-ProgressBar/)
13 exists, and is pretty easy to use:
14
15         my $pos = $sfh->tell();
16     $sfh->seek(0,SEEK_END);
17     my $p = Term::ProgressBar->new({count => $sfh->tell,
18                                         remove => 1,
19                                                                         ETA => 'linear'});
20     $sfh->seek($pos,SEEK_SET);
21     while (<$sfh>) {
22                 ...; # yada yada yada
23                 $p->update($sfh->tell());               
24         }
25
26 producing useful output, which told me that my SQLite database
27 creation routine would take about 2 days to finish instead of the 7
28 years that the slightly less optimal version wanted.
29
30
31 [[!tag tech perl]]