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";
}
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.
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 $!;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With