I am writing a script in perl for my project. I have given a snippet of the files below

start.pl contains:

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

submain.pl contains:

system("/ws/nibalan/submanual.pl")
open(INPUT, ">/users/$login/input");
-
-
some writing into input file

submanual.pl contains:

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


While trying to open manualans.pl in write mode it gave the error NO SUCH FILE OR DIRECTORY. It is trying to open an existing file but I want to create a new file and write into it. But in other scripts I am able to open input file in write mode. Weird that I am getting this error. Can you please help me out. Its urgent.

If you don't test whether each of your open statements succeeded by adding or die $! you won't know which one of them fails. See the simple examples at the beginning of perldoc -f open. Also every script should use strict; use warnings;

Edited 5 Years Ago by d5e5: n/a

I'm curious why you are daisy-chaining all these scripts together this way? One spawns another which spawns another. Is there a reason all of this can't be done in a single script using subroutines?

Also, d5e5 is right on with testing your opens. Here's a simple example:

open(INPUT,">/users/$login/input") or die "Can't open '/users/$login/input': $!\n";

The $! variable at the end will give the current value of the last syscall error.

Edited 5 Years Ago by roswell1329: n/a

This article has been dead for over six months. Start a new discussion instead.