in reply to Getting for() to accept a tied array in one statement
If so, then the behaviour you want is easily achieved using overloaded '<>'.my $iter = TQDM::tqdm(1..10); while (<$iter>) { print "got [$_]\n"; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting for() to accept a tied array in one statement
by perlancar (Hermit) on Apr 16, 2019 at 14:22 UTC | |
by dave_the_m (Monsignor) on Apr 16, 2019 at 15:01 UTC |