in reply to Getting for() to accept a tied array in one statement

There is also the 3-part for:

#!/usr/bin/env perl # author: bliako # for: https://perlmonks.org/?node_id=1232642 # 17/04/2019 use strict; use warnings; package Wrapper; # use: new(code, array) sub new { return bless {s=>$_[1],a=>[@_[2..$#_]],c=>0}, $_[0] } sub next { $_[0]->{s}->(); scalar(@{$_[0]->{a}}) > $_[0]->{c} ? $_[0]->{a}->[$_[0]->{c}++ +] : undef } sub reset { $_[0]->{c} = 0 } package main; for($_=Wrapper->new(sub{print "hello\n"}, 1..10);my $_2=$_->next;){ print "got=$_2\n"; }

bw, bliako