Author Topic: perl training wheels  (Read 3438 times)

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #30 on: 24 September 2002, 01:10 »
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?
Someone please remove this account. Thanks...

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
perl training wheels
« Reply #31 on: 24 September 2002, 03:59 »
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...
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #32 on: 24 September 2002, 04:49 »
good for you
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
perl training wheels
« Reply #33 on: 28 September 2002, 17:16 »
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");
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
Okay, received and understood. BUT i type in ./sample.pl and i get:  
quote:
bash: ./sample.pl: bad interpreter: Not a directory
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.
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #34 on: 28 September 2002, 20:30 »
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: [Select]

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.
Someone please remove this account. Thanks...

beltorak0

  • Member
  • **
  • Posts: 223
  • Kudos: 0
    • http://www.angelfire.com/realm/beltorak
perl training wheels
« Reply #35 on: 30 September 2002, 21:02 »
here's a little tip to help when you don't have access to the server logs:
Code: [Select]

this will (as indicated) send fatal server errors to the browser as well as the error logs (provided they have the CGI/Carp module installed).

hope this helps with future troubleshooting.

-t.
from Attrition.Org
 
quote:
Like many times before, Microsoft is re-inventing the wheel and opting for something other than round.

-t.


Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
perl training wheels
« Reply #36 on: 30 September 2002, 13:23 »
useful information indeed. i will be remembering that.

Voidmain i am a bit clueless as to why this might be happening because i am writing my text file using emacs in linux! i haven't performed that operation that you suggest, i really need to brush up on the use of things like od and tr!

As i write this i am testing this out at home, and still do not have apache configured right. However my question really is, that the tutorial i am doing does not say that apache must be installed and has not in fact mentioned anything of this sort. edit:- sorry, just getting confused, i am attempting to make it work without needing to call perl, not attempting to serve it over the net.

Still, i'm not stumped yet, i'll keep fiddling and see what happens...

edit: thank the gods for shell accounts! i just typed the above <STDIN> file in my Grex account, did a chmod +x, and ran it using ./1stperlscript.pl and hey presto it does exactly what it is supposed to do! without needing to invoke 'perl' on the commandline. Now i just need to get it to work at home. i must be overlooking something simple...

[ September 30, 2002: Message edited by: Calum ]

visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #37 on: 30 September 2002, 17:01 »
quote:
Originally posted by void main:
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.


dos2unix works great. I had to use it onmy messageboard scripts.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #38 on: 30 September 2002, 19:44 »
Calum, the only thing that bugs me is the bash error message "not a directory" that you claim to be getting. If you are trying to run a DOS formatted Perl script you should get a bash error that looks like this:

Code: [Select]

But your "bad interpreter" message definately indicates that the first line in your Perl script is f00ked.  It either doesn't match the location of your perl executable or you have a '\r\n' where there should be a '\n' as I mentioned in the previous post.  Did you follow my message step by step and do the "which perl" and do the "od" commands?  If so I want to see the output from both of those commands.
Someone please remove this account. Thanks...