Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Mkdir failing

by MVRS (Acolyte)
on Dec 02, 2011 at 11:55 UTC ( #941302=perlquestion: print w/replies, xml ) Need Help??
MVRS has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks , 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

please dont mynd if the code is idiotic , as am jus beginner in perl , suggest me the write approach for this script and if any error

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

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"; }

Replies are listed 'Best First'.
Re: Mkdir failing
by bart (Canon) on Dec 02, 2011 at 11:58 UTC
    You can't use mkdir to create deeply nested directories in one go. But you can use make_path (or mkpath) from the (standard) module File::Path to do it for you.

    oh, and you have to remove the newline from the end of each filename. A simple way to do that is using chomp.

      thankyou bart, it worked for me with mkpath
Re: Mkdir failing
by NetWallah (Canon) on Dec 02, 2011 at 16:53 UTC
    One thing to improve your code:
    The construct:
    open ONE,"<","Filename" || die "Cannot open the file ";
    Will not DIE as you expect, due to operator precedence (The 'die' will NEVER get executed).

    The preferred, and correct usage is:

    open my $one ,"<","/var/www/html/piRNA_html/UNAFold/output_folder_1.tx +t" or die "Cannot open the file (ONE): $!"; # Note the use of a block-scoped variable $one, # and "||" replaced by the low-precedence "or" # and "$!" added to provide the OS error message corresponding to +the failure @folder = <$one>; close $one;

                "XML is like violence: if it doesn't solve your problem, use more."

Re: Mkdir failing
by Anonymous Monk on Dec 02, 2011 at 12:09 UTC
    The "idiotic" part you are talking about is not the code quality of a beginner, because that would be petty. It is you not listening to the advice you get.

    In 941236 and 941241 and 941250 and 941277 people were already telling you to print the variable $! to see the error message. Do this.

      thanks anonymous , i changed accordingly as they mentioned previously with $! then am getting error as following Software error: : Cannot make directory /var/www/html/piRNA_html/UNAFold/output/10010 errorwas:Permission denied at /var/www/html/piRNA_html/UNAFold/unafold.cgi line 55. i couldnt understand , y permission denied, though i gave 777 permission in the code, please let me know abt this

        Calling mkdir with a mask of 777 specifies the permissions you want to attribute to the directory you're creating. This does not mean that you'll magically be able to create files or directories in parts of the filesystem where you (the user running the script, note your webserver configiration) lacks permission to do so. See CGI Programming from the tutorials seciton.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://941302]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2018-07-21 23:23 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (450 votes). Check out past polls.