Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Editor Problem

by Likeless (Acolyte)
on Aug 10, 2004 at 15:38 UTC ( [id://381631]=perlquestion: print w/replies, xml ) Need Help??

Likeless has asked for the wisdom of the Perl Monks concerning the following question:

I write my perl code on Textpad 4.5.0 from www.textpad.com running on Windows 98SE, and upload it to a server running perl 5.8.0 on Red Hat Linux 9.0.

The problem I am having is that if I write a perl script in Textpad like this:
#!/usr/bin/perl print "hello world!\n";
I get this:

: bad interpreter: No such file or directory

If I add the -w switch, it works:
#!/usr/bin/perl -w print "hello world!\n";
It also works if I simply write the code direct on the Linux server, using a text editor like pico.

So my question is: Is there any way I can write perl in Textpad without using the -w switch all the time, and if not, is there an alternative text editor with color highlighting you would recommend?

By the way, I am uploading in ASCII mode, not binary.

Thanks for yor help!

Replies are listed 'Best First'.
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.

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 =(.

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;
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

Re: Editor Problem
by wfsp (Abbot) on Aug 10, 2004 at 15:52 UTC
    Are you using Net::FTP?

    I have had a similar problem and found that this fixed it.

    Update: fixed link

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.


    -CSUhockey3
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.

      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.


      -Waswas
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.
      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.
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
      Yes. That was the problem all along. Thank you so much!
Re: Editor Problem
by YuckFoo (Abbot) on Aug 10, 2004 at 17:18 UTC
    I have used this:

    #!/usr/bin/perl --

    It's not documented in perldoc perlrun, but seems to work well as a 'no switch'.

    YuckF--

      -- is documented in every perlrun I've looked at (back through 5.005_04).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://381631]
Approved by csuhockey3
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-10-03 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (42 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.