Mkdir cannot create directory in perl

I think the previously defined script was confusing, this is the script I want to run now that does not create a directory, please help me with this.

I am not mistaken if the code is idiotic, since I'm just a beginner in perl. Could you suggest me the correct approach for this script, and if I get any errors?

output_folder1.txt contains 10010 , and output_folder.txt_2 contains 30001 .

I get the output file could not 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"; } 
+4
source share
3 answers

You need to add $! to your stamp string ( die "File cannot be created: $!" ). This will give you a reason. $! is an error message from the operating system. See "Variable Errors" in perlvar .

It seems quite possible that you are trying to run mkdir two directories at once ( …/$temp2 and …/$temp2/$temp1 ). For this you need two calls to mkdir or use File::Path make_path .

+8
source

You must first check if the $temp2 directory $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 $!; 
+3
source

File :: Path :: make_path combined with Path :: Class (or by itself, if you do not care about a good interface to platform independent paths) should take away most of the pain.

+2
source

Source: https://habr.com/ru/post/1384312/


All Articles