mkdir 无法在 perl 中创建目录

发布于 2024-12-19 13:33:40 字数 909 浏览 0 评论 0原文

我认为之前给出的脚本很混乱,这是我现在要运行的脚本,它没有创建目录,请帮助我。

我不知道代码是否愚蠢,因为我只是 perl 的初学者。您能否建议我该脚本的正确方法以及是否有任何错误?

output_folder1.txt 包含 10010output_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

她比我温柔 2024-12-26 13:33:40

您需要将 $! 添加到您的 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 use File::Path's make_path.

北凤男飞 2024-12-26 13:33:40

您应该首先检查 $temp2 目录是否存在:

unless ( -d "/var/www/html/piRNA_html/UNAFold/output/$temp2" ) {
    mkdir "/var/www/html/piRNA_html/UNAFold/output/$temp2",0777 or die $!;
}
mkdir "/var/www/html/piRNA_html/UNAFold/output/$temp2/$temp1",0777 or die $!;

You should first check if $temp2 directory exists:

unless ( -d "/var/www/html/piRNA_html/UNAFold/output/$temp2" ) {
    mkdir "/var/www/html/piRNA_html/UNAFold/output/$temp2",0777 or die $!;
}
mkdir "/var/www/html/piRNA_html/UNAFold/output/$temp2/$temp1",0777 or die $!;
风吹雨成花 2024-12-26 13:33:40

File::Path::make_pathPath::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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文