tqdm is a Python progress bar/meter library which has a simple interface: you just wrap an iterable:
for i in range(100): ...
with:
for i in tqdm(range(100)): ...
and voila, you have a progress bar. I wonder how we can do something similar in Perl. If we create a tqdm() function which returns a tied array, e.g.:
for (tqdm(1..100)) { ... }
then Perl will FETCH all the items first before starting the loop, defeating the progress measuring.
We can make tqdm() function return a tied scalar for every element, but that will be more inefficient and introduce additional side effects.
We can have tqdm() return a tied scalar, something like:
for (my $i = tqdm(100); $i < 100; $i++) { ... }
but: 1) $i is still a tied scalar; 2) C-style loop is less nice and less often used; 3) the above syntax is repetitive.
Any ideas?
UPDATE 2019-04-16: We did it! In Perl we can indeed support the same syntax by using a combination of tied array and lvalue wrapper. Read all about it in Getting for() to accept a tied array in one statement.
In reply to Porting tqdm to Perl by perlancar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |