sub upto {
my $stop = $_[0];
my $start = 0;
for ($start..$stop) {
yield $_
};
};
for my $item (upto(5)) {
print "At $item\n";
};
__END__
At 1
At 2
At 3
At 4
At 5
####
sub frobnicate {
print "Frobnicating\n";
};
sub frobnitz {
print "Frobnitzing\n";
};
sub gargle {
local *frobnicate = \&frobnitz;
frobnicate();
};
my $thr1 = async { gargle() };
my $thr2 = async { gargle() };
my $thr3 = async { gargle() };
##
##
open my $fh, "<:async", $filename
or die "Couldn't open '$filename': $!";
my $line = <$fh>;
# ... do some busy work without touching $line ...
print $line;