The thing that is still missing in the Perl core for me is more flow control resp. non-linear flow:
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
So far, Coro implements that, but not for Win32/MSVC, and it is not that stable. Also, the libcoro that Coro uses is under the GPL, which prohibits its distribution with the Perl core.
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;
$line should be returned as a tie'd variable and the read request should be run in the background, allowing the foreground program to continue. Any access to $line will then wait until the background read operation has completed.
Update:Upon rereading, I don't need the :Generator syntax on my generators. Just using the yield keyword (similar to return but remember all state so we know where to continue when we get called again) is enough.
In reply to Re: what would you like to see in perl5.12?
by Corion
in thread what would you like to see in perl5.12?
by ysth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |