Follow Ovid's advice and strip CR's from the file (perhaps even automatically, by doing an ASCII instead of BINARY transfer with FTP).

The problem is that the shell expects the shebang line to be terminated with just a newline ('\n'), which it strips off (along with the initial '#!') and then tries to exec what's left. In your case, since the lines are all terminated with CR-LF ('\r\n'), stripping off the newline still leaves a CR at the end of whatever command you have there (i.e., '/usr/bin/perl\r').

By adding the '-w' switch (or *any* valid Perl option, I suspect), you will have changed the command to '/usr/bin/perl -w\r'. In other words, the '\r' is still there, but it is no longer adjacent to the command name, so the shell's shebang handler passes it to the invoked command as an argument(Perl in this case).

Perl views the option string '-w\r' the same as if it were the two separate options, '-w' and '-\r'. Since you mention no warning message (when you use -w), I suppose Perl is choosing to ignore the latter, perhaps because it is a form of whitespace.

Update: Perhaps I forgot to mention this, but if the shell cannot find the command specified on the shebang line, of say 'scriptname.pl', it will report the error with the message,

bash: ./scriptname.pl: No such file or directory

as shown in the original note, 'Odd -w behavior on scripts written on Win32 platform'. What this message means is more like "got a 'No such file or directory' error while trying to execute the file, './scriptname.pl'." The reason it cannot find it, of course, is that there is no binary executable file named '/usr/bin/perl\r (note the a CR character).'

dmm

You can give a man a fish and feed him for a day ...
Or, you can
teach him to fish and feed him for a lifetime

In reply to Re: Odd -w behavior on scripts written on Win32 platform by dmmiller2k
in thread Odd -w behavior on scripts written on Win32 platform by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.