Hi All,

I'm new here so apologies if there's something not quite done right in my first post on here.

I'm fairly new to Perl but this is the first bit I've tried to write at home on my own.

I want to have a .pl file that runs in a browser window by passing html to it then opens a .txt file and reads it's contents into a variable, that I can use else where. I started by getting it to do this but with local files on my laptop which was pretty straightforward.

The problem at the moment is that it says it can't open the file, I'm assuming because I'm not calling it properly as I have ftp access to the files, it's chmod is correct and the path and file name is correct.

Here's the code I've worked out so far by reading up tutorials on the net...

#!/usr/bin/perl

use strict;
use warnings;

print "Content-type: text/html\n\n"; # must send a header first
print "<html>";
print "	<head>";
print "		A box with some text in it...\n<br>";
print "	</head>";
print "	<body>";

if ( $^O eq "MSWin32") { system "dir" or warn "Couldn't run dir $!\n" }
else { print "Not a Windows machine.\n" }

my $INPUT_FILEHANDLE = "input_filehandle"; # open a handle to input text to
my $OUTPUT_FILEHANDLE = "output_filehandle"; # open a handle to output text to

my $INPUT_FILE_NAME = 'd:\domains\jacamar.co.uk\wwwroot\cgi-bin\Text_box_content.txt';

open (INPUT_FILEHANDLE, "<$INPUT_FILE_NAME") or die "<br>Can't open $INPUT_FILE_NAME for reading \"$!\"\n"; # open input file

etc

What it shows is:-

A box with some text in it...

Can't spawn "cmd.exe": No such file or directory at d:\domains\jacamar.co.uk\wwwroot\cgi-bin\page_editor.pl line 15. Can't open d:\domains\jacamar.co.uk\wwwroot\cgi-bin\Text_box_content.txt for reading

I know it can't find cmd.exe as the people who host the server say it's not compatible or something... so why on earth can't if find this Text_box_content.txt???

many thanks in advance for any replies
Sarah

Recommended Answers

All 6 Replies

If the directory and file are correct, I have no idea why perl can't open the file. There is no CHMOD on Windows servers (that I am aware of).

are the ticks and slashes the right way round as far as you know? as in DOS the slashes go one way and in perl the other and then when you're putting it out to an html page you have to escape the slashes and I'm sure there's more syntax rules that I haven't yet come across!

Your file paths are windows, not DOS. Windows supports forward and backslashes in directory paths, but its safer to use forward slashes because the backslash is a special character in perl. If by ticks you mean quotes, the quotes in your code look OK to me.

What server you are using to run your .pl file? As far as i know, diff. web servers require to keep files in diff. hierarchy of folders in server installation path. For eg.(in Apache web server) you need to keep .pl files in ../cg-bin and like wise.

May be that is the problem, im not sure. Keep your input file in directory as your source file, then try.

katharnakh.

What server you are using to run your .pl file?

on a windows server and both files are in the cgi-bin.

As far as i know, diff. web servers require to keep files in diff. hierarchy of folders in server installation path. For eg.(in Apache web server) you need to keep .pl files in ../cg-bin and like wise.

May be that is the problem, im not sure. Keep your input file in directory as your source file, then try.

Does it need the full path like I've given it or does it need one like this:-

http://www.jacamar.co.uk/cgi-bin/page_editor.pl

This is the file that I'm running if it's helpful to see it in action.

many thanks

sussed it! I took out all unnecessary lines - including the "if" statement and it works fine now - phew! :)

thanks all for your help

Sarah

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.