2024年4月19日发(作者:)
perl函数集
一、进程处理函数
1、进程启动函数
2、进程终止函数
3、进程控制函数
4、其它控制函数
二、数学函数
三、字符串处理函数
四、标量转换函数
五、数组和列表函数
六、关联数组函数
一、进程处理函数
1、进程启动函数
函数名 eval
调用语法 eval(string)
解说 将string看作Perl语句执行。
正确执行后,系统变量$@为空串,如果有错误,$@中为错误信息。
例子 $print = "print ("hello,worldn");";
eval ($print);
结果输出 hello, world
函数名 system
调用语法 system(list)
解说 list中第一个元素为程序名,其余为参数。
system启动一个进程运行程序并等待其结束,程序结束后错误代码左移八位成为返回
值。
例子 @proglist = ("echo", "hello,world!");
system(@proglist);
结果输出 hello, world!
函数名 fork
调用语法 procid = fork();
解说 创建程序的两个拷贝--父进程和子进程--同时运行。子进程返回零,父进程返回
非零值,此值为子程序的进程ID号。
例子 $retval = fork();
if ($retval == 0) {
# this is the child process
exit; # this terminates the child process
} else {
# this is the parent process
}
结果输出 无
函数名 pipe
调用语法 pipe (infile, outfile);
解说 与fork合用,给父进程和子进程提供通信的方式。送到outfile文件变量的信息
可以通过infile文件变量读取。步骤:
1、调用pipe
2、用fork将程序分成父进程和子进程
3、一个进程关掉infile,另一个关掉outfile
例子 pipe (INPUT, OUTPUT);
$retval = fork();


发布评论