mkdir 无法在 perl 中创建目录
我认为之前给出的脚本很混乱,这是我现在要运行的脚本,它没有创建目录,请帮助我。
我不知道代码是否愚蠢,因为我只是 perl 的初学者。您能否建议我该脚本的正确方法以及是否有任何错误?
output_folder1.txt
包含 10010
,output_folder.txt_2
包含 30001
。
我收到无法创建输出文件。
#!/usr/local/bin/perl -w
use strict;
print "Content-type:text/html\n\n";
my(@folder_name,$temp1,$temp2);
open ONE,"<","/var/www/html/piRNA_html/UNAFold/output_folder_1.txt" || die "Cannot open the file";
@folder_name=<ONE>;
close ONE;
open TWO,"<","/var/www/html/piRNA_html/UNAFold/output_folder_2.txt" || die "Cannot open the file";
push(@folder_name,<TWO>);
close TWO;
print $folder_name[0],"\n",$folder_name[1],"\n";
$temp1 = pop(@folder_name);
$temp2 = pop(@folder_name);
if($temp1 < 30050)
{
mkdir "/var/www/html/piRNA_html/UNAFold/output/$temp2/$temp1",0777 or die "File cannot be created";
}
i think the script previously given was confusing ,this is the script i want to run now, which is not creating directory, please help me in this.
I don't mynd if the code is idiotic , as I am just a beginner in perl. Could you suggest me the right approach for this script, and if I have any errors?
The output_folder1.txt
contains 10010
, and output_folder.txt_2
contains 30001
.
I am getting output file cannot be created.
#!/usr/local/bin/perl -w
use strict;
print "Content-type:text/html\n\n";
my(@folder_name,$temp1,$temp2);
open ONE,"<","/var/www/html/piRNA_html/UNAFold/output_folder_1.txt" || die "Cannot open the file";
@folder_name=<ONE>;
close ONE;
open TWO,"<","/var/www/html/piRNA_html/UNAFold/output_folder_2.txt" || die "Cannot open the file";
push(@folder_name,<TWO>);
close TWO;
print $folder_name[0],"\n",$folder_name[1],"\n";
$temp1 = pop(@folder_name);
$temp2 = pop(@folder_name);
if($temp1 < 30050)
{
mkdir "/var/www/html/piRNA_html/UNAFold/output/$temp2/$temp1",0777 or die "File cannot be created";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将
$!
添加到您的 die 字符串中(die “无法创建文件:$!”
)。这会给你原因。$!
是来自操作系统的错误消息。请参阅 perlvar 中的“错误变量”。您似乎很可能尝试同时 mkdir 两个目录(
…/$temp2
和…/$temp2/$temp1
)。您需要两次 mkdir 调用,或者使用File::路径
的make_path
。You need to add
$!
to your die string (die "File cannot be created: $!"
). That'll give you the reason why.$!
is the error message from the operating system. See "Error Variables" in perlvar.It seems quite possible you're trying to mkdir two directories at once (
…/$temp2
and…/$temp2/$temp1
). You need two mkdir calls for that, or useFile::Path
'smake_path
.您应该首先检查
$temp2
目录是否存在:You should first check if
$temp2
directory exists:File::Path::make_path 与 Path::Class (或者单独使用,如果您不关心平台独立路径的良好接口)应该承担大部分的痛苦 离开。
File::Path::make_path in conjunction with Path::Class (or on its own, if you don't care about the nice interface to platform independent paths) should take most of the pain away.