问个问题

问个问题

问个问题
问个问题,下边的程序中,spawn sub {。。。}是什么意思啊?
就是调用子函数吗?


。。。
spawn sub {
print "Hello there, $name, it's now ", scalar localtime, "\n";
exec '/usr/games/fortune'
or confess "can't exec fortune: $!";
};
。。。
sub spawn {
my $coderef = shift;
unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
confess "usage: spawn CODEREF";
}
my $pid;
if (!defined($pid = fork)) {
logmsg "cannot fork: $!";
return;
} elsif ($pid) {
logmsg "begat $pid";
return; # i'm the parent
}
# else i'm the child -- go spawn
open(STDIN, "<&Client") or die "can't dup client to stdin";
open(STDOUT, ">&Client") or die "can't dup client to stdout";
STDOUT->autoflush();
exit &$coderef();
}
sub{...} 是一个函数的引用
spawn sub{...} 是将 sub{...}的引用作为参数,调用 spawn 这个函数
就好像
$ref = sub {...};
spawn($ref);
3x.