CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
No such file or directory error

 



nibalan
Novice

Jun 12, 2011, 10:41 PM

Post #1 of 8 (880 views)
No such file or directory error Can't Post

start.pl contains:

system("/ws/nibalan/submain.pl");

submain.pl contains:

system("/ws/nibalan/submanual.pl")

submanual.pl contains:

open(INPUT, "/users/$login/input");
open(MANUALANS, ">/users/$login/manualans.pl");
-
-
some writing into manualns.pl file



The above code works fine for me. input and manualans.pl file are created in /users/$login directory. Now I thought of creating a directory under /users/$login and create all the above files under it. Modified code:

start.pl contains:

mkdir "/users/$login/$viewtag", 0777 unless -d "$viewtag";
system("/ws/nibalan/submain.pl");

submain.pl contains:

system("/ws/nibalan/submanual.pl")

submanual.pl contains:

open(INPUT, "/users/$login/$viewtag/input");
open(MANUALANS, ">/users/$login/$viewtag/manualans.pl");
-
-
some writing into manualns.pl file


Now te directory got created successfully and input file also got created but manualans file is not getting created. I get the error No such file or directory. I have given the absolute path correctly. Also tried to manually change the permission of directory to 777. Still no use. Can you please help out?


rovf
Veteran

Jun 13, 2011, 5:25 AM

Post #2 of 8 (878 views)
Re: [nibalan] No such file or directory error [In reply to] Can't Post

You did not say on which statement you received the error message - I guess it's on the first "open", but you should always be precise when posting such problems.

What do you see when you put the following statements just before your two "open" calls in submanual.pl:


Code
{  
use strict; use warnings FATAL => qw(all);
print "login='$login'\n";
system("ls -lR '/users/$login'");
}



nibalan
Novice

Jun 13, 2011, 8:02 AM

Post #3 of 8 (876 views)
Re: [rovf] No such file or directory error [In reply to] Can't Post

I mentioned that manualans file is not opening that is the second open statement in the code.


nibalan
Novice

Jun 13, 2011, 8:25 AM

Post #4 of 8 (873 views)
Re: [rovf] No such file or directory error [In reply to] Can't Post

On adding your code before the two open statements the contents of all directories got listed under my users directory. The manualans file did not get created


FishMonger
Veteran / Moderator

Jun 13, 2011, 8:25 AM

Post #5 of 8 (873 views)
Re: [nibalan] No such file or directory error [In reply to] Can't Post

How are you getting the error "No such file or directory" when your open calls don't include the necessary code/checks that would have returned such an error message.

Please post your actual code and not some approximate representation of it.

EVERY Perl script you write should include the following 2 pragmas. Please add them to your scripts.

Code
use strict; 
use warnings;


For creating the directories, use the File::Path module. http://search.cpan.org/~dland/File-Path-2.08/Path.pm


nibalan
Novice

Jun 13, 2011, 9:36 PM

Post #6 of 8 (862 views)
Re: [FishMonger] No such file or directory error [In reply to] Can't Post

Actually I did get this "No such file or directory error" on giving the below statement:

open(MANUALANS, ">/users/$login/$viewtag/manualans.pl") or die $!;

That is why I am getting confused. Instead of opening in write mode it is trying to open an existing file, which it should not do


rovf
Veteran

Jun 13, 2011, 11:20 PM

Post #7 of 8 (859 views)
Re: [nibalan] No such file or directory error [In reply to] Can't Post

The error likely means that /users/$login/$viewtag does not exist.

As an experiment, you could try to shell out:

my $dir="/users/$login/$viewtag";
$|=1;
print "About to create file in '$dir'...\n";
if(!open(MANUALANS,'>',"$dir/manualans.pl")) {
print "ERROR: $!\n";
system("ls -la $dir");
system;
die;
}

This would put you on the shell in exactly that context which existed in the program, and you could try to create the file manually and see whether you maybe get a different error.

BTW, when replying on these suggestions, you should always include the few lines of code which are of interest, plus copy and paste the actual output you receive.


FishMonger
Veteran / Moderator

Jun 14, 2011, 7:18 AM

Post #8 of 8 (853 views)
Re: [nibalan] No such file or directory error [In reply to] Can't Post

This line throws up a "red flag" for me.

Code
mkdir "/users/$login/$viewtag", 0777 unless -d "$viewtag";

You're specifying the full path for mkdir, but your unless clause only specifies the final directory without the path leading upto it. Are you actually in the "/users/$login/" directory when you execute that mkdir command? If not, then that would explain one of the possible reasons why the directory isn't being created.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives