Re: Editor Problem
by atcroft (Abbot) on Aug 10, 2004 at 15:48 UTC
|
I would hazard a guess that for some reason your ftp program is still transferring it as a binary, perhaps because it doesn't recognize the extension on the file as one to handle as a text file. To determine this, I can think of several ways:
- try od -c filename, and look for '\r\n' pairs
- open it in vi, where you would see ^M on the end of the line ( ':q' to exit )
- upload the first version, then try perl -p -i -e 's/\r//g' filename -if it works after this (which removes the character in question), then it is indeed uploading it as binary (this also works to fix the problem, if you want to continue to use TextPad and don't mind the extra step).
Hope that helps.
| [reply] [d/l] [select] |
Re: Editor Problem
by deibyz (Hermit) on Aug 10, 2004 at 15:42 UTC
|
I have had the same problem, caused by the different line endings for Windows and Linux. Running dos2unix or any similar utility against your script should work. BTW, uploading as ASCII should have avoided this problem.
Update: I use UltraEdit when I have to edit perl code on Windows, but it's not free software =(. | [reply] [d/l] |
Re: Editor Problem
by Joost (Canon) on Aug 10, 2004 at 15:47 UTC
|
By the way, I am uploading in ASCII mode, not binary.
Then your FTP client or the server is broken, or your file was saved with Mac line endings, but most likely you are NOT uploading in ASCII mode.
Is there any way I can write perl in Textpad without using the -w switch
You can, always, but for CGI scripts you should use strict, warnings and taint mode.
#!/usr/bin/perl -wT
use strict;
| [reply] [d/l] |
Re: Editor Problem
by Grygonos (Chaplain) on Aug 10, 2004 at 16:34 UTC
|
From TextPad, Do: File->Save As. In the combo box labeled File Format, choose UNIX rather than PC. This should fix it, if in fact it is a PC rather than UNIX line ending issue.
edit: That is assuming your FTP client is uploading it properly in ASCII
| [reply] |
Re: Editor Problem
by wfsp (Abbot) on Aug 10, 2004 at 15:52 UTC
|
| [reply] [d/l] |
Re: Editor Problem
by csuhockey3 (Curate) on Aug 10, 2004 at 15:43 UTC
|
There are plenty of alternative editors -- I suggest you use something other than textpad. have a look at this thread about
editors, it should give you some ideas to try something new.
| [reply] |
Re: Editor Problem
by Crackers2 (Parson) on Aug 10, 2004 at 15:46 UTC
|
I suspect your ASCII upload doesn't convert CR/LF into CR as you seem to be expecting. IIRC FTP relies on the file's extension to decide whether a file needs conversion or not, and your file doesn't match whatever list your FTP client has.
Try doing a dos2unix on your file after the tranfer and see if that makes it work.
| [reply] [d/l] |
|
That is not true, Some Windows FTP clients look at the extension to try to determine how to send files. Most do not (even in windows). They rely on the settings in the application bin/ascii or auto. And also they usually try to figure out what OS the FTP server is running and that changes the ASCII sending behavior on many of them. Bottom line is you cant depend blankly on any windows FTP client to handle ascii type sends, you need to verify and test how they behave and then only count on what you have verified.
| [reply] |
Re: Editor Problem
by Likeless (Acolyte) on Aug 10, 2004 at 19:44 UTC
|
If anyone is curious, here are some test results based on your advice:
I downloaded and tried out optiperl and, making sure to switch the files to "Unix Format", got exactly the same results as with textpad.
I ran od -c on it, and it showed lots of \r\n pairs.
I then ran dos2unix on the file, and that fixed the file so it worked.
I then downloaded the file, changed its name, and uploaded it again. It still worked, so I don't think the problem is with the FTP client (which, incidentally, I run in "always ASCII" mode).
I also tried the -- switch, which made the script run too.
Incidentally, I have very good reasons for avoiding the -w switch, which you can read about here if you are curious.
Thank you all for your advice. I have a working solution now, but no real understanding why my perl scripts are always created with \r\n pairs. I will try a couple more editors. | [reply] [d/l] |
|
The problem is definately with your ftp client. Otherwise the \r\n would become \n on upload, and the \n would become \r\n on download.
| [reply] |
Re: Editor Problem
by astroboy (Chaplain) on Aug 11, 2004 at 12:28 UTC
|
I don't know what FTP server is used with RH9, but RH8 uses vsftp, and by default it ignores the "ascii" command and will transfer everything as binary. To fix set:
ascii_upload_enable=YES
ascii_download_enable=YES
in the vsftpd.conf file. It's a pretty patronising server. It tells you "ascii tastes bad, dude" in its oh-so-hip surfy language whenever you try setting the transfer mode to ascii | [reply] [d/l] |
|
Yes. That was the problem all along. Thank you so much!
| [reply] |
Re: Editor Problem
by YuckFoo (Abbot) on Aug 10, 2004 at 17:18 UTC
|
#!/usr/bin/perl --
It's not documented in perldoc perlrun, but seems to work well as a 'no switch'.
YuckF-- | [reply] [d/l] |
|
-- is documented in every perlrun I've looked at (back through 5.005_04).
| [reply] |