Is it an absolute requirement to have all the code within the while/for expression? I.e. is the following acceptable:
my $iter = TQDM::tqdm(1..10);
while (<$iter>) {
print "got [$_]\n";
}
If so, then the behaviour you want is easily achieved using overloaded '<>'.
Otherwise, I think you need a custom iterator function, e.g.
sub iterate ($&) {
my ($ary, $code) = @_;
for (@$ary) {
print "progress bar: $_\n";
$code->();
}
}
sub tqdm { bless [ @_ ] }
iterate tqdm(1..10), sub {
print "got [$_]\n";
};
Dave.