操作系统志愿军

奉献你的诀窍让我们一起分享.给出你的疑难让我们一起讨论.

78 成员168 主题192 回复0 张照片

perl(7)

Y
ytbszl80
2001-01-29 16:58
open(filehandle,"<$filename")
说明:打开一个文件(read only)
eg:$filename="path/cgi.txt";
open(file,"<$filename")||die "can not open $filename\n";
@array=<file>;
close(file);
print"@array";

open(filehandle,">$filename")
说明:建立一个文件如果文件已经存在就覆盖它,并把数据写入这个文件中!!
eg:$filename="path/cgi.txt";
open(file,">$filename")||die"can not open $filename\n";
print file"this is a new line1\n";
print file"this is a new line2\n";
close(file);
备注:这时文件中有this is a new line1,this is a new line2这两行!!

open(filehandle,">>$filename")
说明:数据用附加的方式写入一文件(write only),如果指定的文件名不存在的话,就会建立一个新的文件.
eg:$filename="path/cgi.txt";
open(file,">>$filename")||die"can not open $filename\n";
print file"this is a new line1\n";
print file"this is a new line2\n";
close(file);

指令:close
语法:close(filehandle)
无需过多的说明了!!

指令:pack
语法:pack("指定的格式",list)
说明:将一个list变成所指定的二进制数格式.
eg:$string=pack("c",65);此时string是A

指令:read
语法:read(filehandle,$string,length)
说明:length 是代表读入的字符串的长度(bytes).用read函数把filehandle众的数据以指定的字符串长度读入之后指派给$string这个变量.在CGI程序的分割解码过程中,如果form的传送方式是设定的post的话,就会将传送的数据社定位标准的输入,所议会将数据内容指定位标准输入,说议会将数据内容给stdin这个标准的filehandle,而CGI环境变量$env('content_length')就是代表使用者的送出的数据的长度,因此我们要用read这个函数来取得使用这送出的数据内容~!
eg:read(stdin,$buffer,$env('content_length'));
将stdin这个标准输入filehandle中的数据以指定的字符串长度读入,再指派给$buffer这个变量!!
1 / 1

登录后回复。