Linux伊甸园论坛 » PHP,PERL,Python » 请问用perl怎样创建一个文件?
初来乍到
注册用户
查看详细资料
TOP
unless (-e $dir_tmpfile){ open(FILE,">$dir_tmpfile") or &out_err("sorry,\t","The tmpfile is not exists!"); //创建文件并写入,失败的话执行out_err }
chomp($dir_tmpfile=<STDIN>); //输入文件名 unless (-e $dir_tmpfile){ print "File not found.\n"; open(FILE,">$dir_tmpfile") or die "Couldn't open $dir_tmpfile:$!"; //创建文件并写入 print FILE "New file.\n"; //在新文件中写入字符串“New file.” } else { print "File found.\n"; } close FILE;
chmod 0755,$dir_tmpfile; #注意这里的755是8进制数,所以最前面的0不能省,这点和shell中不一样