in reply to what would you like to see in perl5.12?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: what would you like to see in perl5.12?
by Jenda (Abbot) on Aug 20, 2007 at 14:33 UTC | |
by Corion (Patriarch) on Aug 20, 2007 at 15:36 UTC | |
by Jenda (Abbot) on Aug 20, 2007 at 23:00 UTC | |
|
Re^2: what would you like to see in perl5.12?
by blazar (Canon) on Aug 20, 2007 at 20:44 UTC | |
by TimToady (Parson) on Aug 21, 2007 at 17:02 UTC | |
by blazar (Canon) on Aug 21, 2007 at 17:47 UTC | |
by TimToady (Parson) on Aug 21, 2007 at 18:31 UTC |