use strict; use Coroutine; sub create : coroutine { my $foo = shift; my @bar = @_; yield{ print "$_\n" for @bar; $foo++; } yield{ print "$foo\n"; rand() > .5 ? 'weird' : ++$foo; } yield{ print "The end is near - goodbye cruel "; pop @bar; } } my $wacky = create(42, 'hello', 'world'); print $wacky->(42, 'hello', 'world'), "\n"; print $wacky->(), "\n"; print $wacky->(), "\n"; print $wacky->(), "\n"; __END__ hello world 42 43 44|weird The end is near - goodbye cruel world