Welcome to WebmasterWorld Guest from 54.226.133.245

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Help with line of Perl code

Problem with perl coding

     
12:45 pm on Apr 17, 2007 (gmt 0)

New User

5+ Year Member

joined:Apr 17, 2007
posts:1
votes: 0


Hi All,

I am not a programmer but have a perl programme which I have recently transferred from a NT4 server to a Windows 2003 server. Everything else is the same except possibly a different version of Perl is running on the server.

I get the following error message:

Software error:
couldn't open datafile No such file or directory at D:\FTP\cym\Htdocs\cgi-bin\inn-i.pl line 1405.For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.

The code around line 1405 is as follows:

print $IN->header;
print $IN->start_html("Innovation Software Superuser Maintenance Page");
open IN, "<$datafiles/maint.html" or die "couldn't open datafile $!";
while (my $line = <IN>){
$line =~ s/_INN_EXEC_/$inn_exec/g;
print $line;
}

And the file containing the datafiles reference says:

$datafiles = 'D:\FTP\cym\htdocs\cgi-bin\inn-i';

I can confirm that this folder exists and maint.html exists.

Could anyone help me correct the error please?

Thanks,

Chris

1:18 pm on Apr 17, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 28, 2002
posts:505
votes: 0


Can't help you much on this one, but for further debugging I would extend the `die`-string to include the $datafiles variable to get an idea of its exact content at the time the script breaks, and then start from there:
... or die "couldn't open datafile $datafiles -- $!";

Kind regards,
R.

1:40 pm on Apr 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


ok, I think this is it.

Take the filename in your open statement:

$datafiles/maint.html

and resolve $datafiles

D:\FTP\cym\htdocs\cgi-bin\inn-i/maint.html

See that? Try changing your open line to "<$datafiles\\maint.html". You have to use a double \ as it's a special character.

5:38 pm on Apr 17, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


this is not a problem:

D:\FTP\cym\htdocs\cgi-bin\inn-i/maint.html

but it's a good habit to get into to use all forward slashes in directory paths, even if you are on windows, it will not matter:

D:/FTP/cym/htdocs/cgi-bin/inn-i/maint.html

this avoids unwanted meta character interpolation if you use the back-slashes in a string that gets interpolated. In this case, the single-quotes would have avoided that but still better to use forward-slashes as a rule.

The problem appears to be that the path or the filename is not correct.

10:07 pm on Apr 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


Thanks perl_diver, I have used both on Win32, but didn't know about mixing them.

In that case the only thing I could suggest is that maybe inn-i isn't supposed to be in the path, or maybe the maint.html is in the wrong directory. It may be a security issue, if you're on Windows Server you're probably using IIS, check that IUSR_#*$!#*$!x has access to the file.

Also try Romeo's suggestion of adding $datafiles to the error message, this will allow you to definitively check the correct path.

1:06 am on Apr 18, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


"No such file or directory" means it can't be found. "Permission denied" would mean the file is either open (a windows thing) or the user (or maybe the script) does not have permission.
4:27 am on Apr 18, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


$datafiles = 'D:\FTP\cym\htdocs\cgi-bin\inn-i';

could it be a case sensitivity problem?
i noticed your error message refers to this directory with an uppercase H for "Htdocs" in the script path:

couldn't open datafile No such file or directory at D:\FTP\cym\Htdocs\cgi-bin\inn-i.pl line 1405...
11:24 am on Apr 18, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


Nope, Windows filesystem is not case sensitive.
2:14 pm on Apr 19, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 2, 2005
posts:70
votes: 0


$datafiles = 'D:/FTP/cym/htdocs/cgi-bin/inn-i';

$file = $datafiles.'/maint.html';
open (IN, "< $file") or die "couldn't open datafile $file $!";

I think you had two problems the \ instead of / and the concentrated string in the open function.