Miscellaneous > Programming & Networking

perl training wheels

<< < (7/8) > >>

voidmain:
It definately appears to be executing your script. Now the question is, do you have access to the web server error logs?  That would be the easiest way to see what is wrong.  But failing that there are pretty common things that can cause that problem. Incorrect headers are common. Can you post a copy of your script so I can take a look at it and test it on my system?

Calum:
no i don't have access to the server logs unfortunately...

i found out what the problem was. unicode text rather than ansi code, whatever the difference is (i don't even know) it turned out to be the difference.

I noticed since i made the text file in win2000 notepad, and then i opened it now in win9x notepad and hey presto, fucked text!!! hooray! so now it is fixed. The code is identical to that in the first post, (edit - i changed the link, but that's it) and now it works there's going to be no stopping me...  ;)

thanks folks for helping me. I still haven't got apache set up at home of course, i'll read up on it myself before i ask questions about that though...

Master of Reality:
good for you

Calum:
hello again:

Perl:


On my home machine i am trying to write basic perl stuff to learn it. i cannot seem to get my scripts to run without calling perl. here is what i mean: i have a page telling me to write the following into a text file:  
quote:#!/usr/bin/perl

$inputline = <STDIN>;
print ("$inputline");
--- End quote ---
Now of course i can see easily what this does and when i execute it with "perl sample.pl" it works fine. The page however says this:  
quote:1) type in the program and save it to a file (in subsequent steps assume the file is called foo)
2) tell the system that this file contains executable commands. To do this enter the command 'chmod +x foo'
3) run the program by entering the command foo
if you receive the error message foo not found or an equivelant, either enter the command ./foo or add the current directory to your PATH environment variable
--- End quote ---
Okay, received and understood. BUT i type in ./sample.pl and i get:  
quote:bash: ./sample.pl: bad interpreter: Not a directory
--- End quote ---
i have verified that perl is indeed installed in /usr/bin/perl and i don't know what is going on. i suspect it is very simple so what is the situation please?

as always, thank you in advance.

voidmain:
I suspect you are writing this code on a Windows machine (using notepad for example) as this is a common issue since DOS/Windows text files are not the same as UNIX text files. Is this the case with you? I went over this with people in the past on this site about why this occurs and how to fix it.

DOS/Windows text file lines are terminated with a CR (Carriage Return) and an LF (Line Feed). Lines in UNIX text files are terminated with LF only. If you try to run a Perl script in UNIX and the first important line "#!/usr/bin/perl" is terminated with a CR/LF your program will spit out a "bad interpereter" message.

First of all, make sure your path to your perl interpereter is correct. Type "which perl". It should spit out "/usr/bin/perl", in which case your script has the right first line with the possible exception of the CR/LF.  To tell if that is the case type this:

$ head -1 sample.pl | od -c

which should spit this out:


--- Code: ---
--- End code ---

Notice the "\n" at the end. If it shows "\r \n" then it is a DOS/Windows file and you need to strip out the CRs. The best solution is not to use that nasty icky Windows to write your Perl code. But you can strip the CRs by:

$ tr -d '\r' < sample.pl > unixsample.pl
$ mv unixsample.pl sample.pl
$ chmod +x sample.pl
$ ./sample.pl

You may also have a utility called "dos2unix" installed on your system that does the same thing, or you can download that utility and install it. It's just a tiny utility which will strip the CRs from a file. With my example using the "tr" command you need to make sure the file you are redirecting to is a new file and don't use the same file name for both input and output, then of course you will have to set the executable bit on that new file before you run it and replace the original file with it. The dos2unix utility does all of this automatically.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version