User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 429,739 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,978 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 540 | Replies: 6
Reply
Join Date: Jun 2008
Posts: 11
Reputation: Scruffstone is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scruffstone Scruffstone is offline Offline
Newbie Poster

Opening a html file on a server from a perl script

  #1  
Jun 3rd, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 622
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 33
KevinADC's Avatar
KevinADC KevinADC is online now Online
Practically a Master Poster

Re: Opening a html file on a server from a perl script

  #2  
Jun 3rd, 2008
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).
Reply With Quote  
Join Date: Jun 2008
Posts: 11
Reputation: Scruffstone is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scruffstone Scruffstone is offline Offline
Newbie Poster

Re: Opening a html file on a server from a perl script

  #3  
Jun 3rd, 2008
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!
Reply With Quote  
Join Date: Mar 2006
Posts: 622
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 33
KevinADC's Avatar
KevinADC KevinADC is online now Online
Practically a Master Poster

Re: Opening a html file on a server from a perl script

  #4  
Jun 3rd, 2008
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.
Reply With Quote  
Join Date: Jan 2006
Posts: 221
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Opening a html file on a server from a perl script

  #5  
Jun 4th, 2008
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.
Last edited by katharnakh : Jun 4th, 2008 at 12:26 am.
challenge the limits
Reply With Quote  
Join Date: Jun 2008
Posts: 11
Reputation: Scruffstone is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scruffstone Scruffstone is offline Offline
Newbie Poster

Re: Opening a html file on a server from a perl script

  #6  
Jun 4th, 2008
Originally Posted by katharnakh View Post
What server you are using to run your .pl file?


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

Originally Posted by katharnakh View Post
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
Reply With Quote  
Join Date: Jun 2008
Posts: 11
Reputation: Scruffstone is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scruffstone Scruffstone is offline Offline
Newbie Poster

Re: Opening a html file on a server from a perl script

  #7  
Jun 4th, 2008
sussed it! I took out all unnecessary lines - including the "if" statement and it works fine now - phew!

thanks all for your help

Sarah
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Perl Forum

All times are GMT -4. The time now is 3:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC