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

I wanted to take the -w off of a couple of my production scripts that are running well, but I'm having a weird problem. I take off the -w and i get an error from apache saying it cannot find the file anymore... It's the only change I'm making. Strange enough, when I then put it back - it works again just as before. Any ideas?

"sometimes when you make a request for the head you don't
want the big, fat body...don't you go snickering."
                                         -- Nathan Torkington UoP2K a.k.a gnat

Replies are listed 'Best First'.
Re: -w more than a warning?
by Fastolfe (Vicar) on Oct 24, 2000 at 18:15 UTC
    Your file has a bunch of binary carriage returns in it. Looks like you did not correctly transfer the file from a non-Unix OS to Unix (or vice-versa) in ASCII form. The problem occurs because *with* the -w flag, the carriage return can be safely ignored by Perl, however, without it, your line looks something like this:
    #!/usr/bin/perl^M
    Since the carriage return has to be treated as if it were a normal ASCII byte, it's looking for the binary perl^M to execute your script, not perl. Thus, you get "not found".

    The fix: Transfer the file again correctly, dropping the carriage returns. Alternatively, you can use the search/replace feature in, say, vi, to strip them out: :%s/^V^M//g (where the ^V is a control-V (quote the next character) and the ^M is a control-M), or use something similar in a Perl one-liner.

      You can also do the following, which is a little easier, IMHO.
      vi nastyDOSfile.pl :set ff=unix :wq
      'ff' is a synonym for 'fileformat'. I imagine there's some useful little command line utility that could process all the files in a directory, but I'm not THAT much of a Unix hack.

      --Chris

      e-mail jcwren

        You mean Perl? (:

        perl -pi.dos -e 's/\r//'

        Doing this under DOS is harder since you have to get the calls to binmode thrown in at the right places. I think you can check the FAQ for more info.

                - tye (but my friends call me "Tye")

      yes, that does appear to be it....

      this script was written by a co-worker who does his editing on win32...I've never seen this before...very interesting. Anyway, i've had him set his editor up to output in UNIX format so all should be well.

      "sometimes when you make a request for the head you don't
      want the big, fat body...don't you go snickering."
                                               -- Nathan Torkington UoP2K a.k.a gnat

RE: (first lines of script) -w more than a warning?
by jptxs (Curate) on Oct 24, 2000 at 17:57 UTC

    as requesed by tye : )

    $ cat -vet rep_input.cgi #!/usr/bin/perl -w ^M$ ^M$ use strict;^M$ use CGI qw(:all);^M$ require 'include.pl';^M$ $! = 1;^M$ print header; ^M$ use DBI;^M$ ^M$ my $REP_FNAME^I^I= uc( param('rep_fname') ); ^M$ my $REP_LNAME^I^I= uc( param('rep_lname') ); ^M$

    "sometimes when you make a request for the head you don't
    want the big, fat body...don't you go snickering."
                                             -- Nathan Torkington UoP2K a.k.a gnat