Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Odd -w behavior on scripts written on Win32 platform

by dmmiller2k (Chaplain)
on Jan 03, 2002 at 02:01 UTC ( [id://135814]=note: print w/replies, xml ) Need Help??


in reply to Odd -w behavior on scripts written on Win32 platform

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

Replies are listed 'Best First'.
Re: Re: Odd -w behavior on scripts written on Win32 platform
by elwarren (Priest) on Jan 03, 2002 at 03:39 UTC
    Following TMTOWTDI, you could create a symbolic link to perl^M in your path. Then hack perl to handle/strip ^M at the end of every line. But it's probably easier to just fix the files :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found