Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Don't want to have to use -w

by Benahimvp (Initiate)
on Jul 17, 2002 at 18:13 UTC ( #182536=perlquestion: print w/ replies, xml ) Need Help??
Benahimvp has asked for the wisdom of the Perl Monks concerning the following question:

I'm a newbie to this site and I wasn't sure whether to post this in this category or debuggin. I'm running Perl 5.6 on a Linux box running Apache. So I created this test script:
#!/usr/bin/perl use CGI; require "../common.sub"; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; print "Hello World";
and it wouldn't work on the web. I checked the server error logs and it said something about premature end of script. However when I ran it from the command line, it worked just fine. I searched the Perl forum cuz I knew something like this was probably common. I found out that if I put the "-w" option with the shebang line, it works fine on the web. So I have two questions. Why is that? And what do I need to do so that I don't have to use -w? You see I'm moving my site from a Win NT computer to a Linux cluster. I never had to use the -w on the Windows computer, but now I do. I thought Perl on Windows is the same as Perl on Linux. I don't want to have to go back through all my scripts and add in -w just so it would work. So how can I make it work without "-w"? I've asked this question and two other forums and people still haven't been able to figure out why this happens. Thanks for your help.

Replies are listed 'Best First'.
Re: Don't want to have to use -w
by DamnDirtyApe (Curate) on Jul 17, 2002 at 18:38 UTC
    I don't want to have to go back through all my scripts and add in -w just so it would work.

    It's not as hard as you might think:

    perl -p -i.bak -e 's/^(#!.*perl)/$1 -w/' *.pl
Re: Don't want to have to use -w
by DamnDirtyApe (Curate) on Jul 17, 2002 at 18:32 UTC

    From perldoc perlrun:

    -w prints warnings about dubious constructs, such as variable names that are mentioned only once and scalar variables that are used before being set, redefined subroutines, references to undefined file­ handles or filehandles opened read-only that you are attempting to write on, values used as a number that doesn't look like numbers, using an array as though it were a scalar, if your subroutines recurse more than 100 deep, and innumerable other things. This switch really just enables the internal "^$W" variable. You can disable or promote into fatal errors specific warnings using "__WARN__" hooks, as described in the perlvar manpage and the warn entry in the perlfunc manpage. See also the perldiag man­ page and the perltrap manpage. A new, fine-grained warning facility is also available if you want to manipulate entire classes of warnings; see the warn­ ings manpage or the perllexwarn manpage.

    Adding -w to your code should not affect whether or not your code runs; it should just give you a better idea why when it doesn't.

    Another option is to use the use warnings pragma in your code.

Re: Don't want to have to use -w
by BrowserUk (Pope) on Jul 17, 2002 at 20:34 UTC

    Small (potential) clarification.

    The winNT box probably had a file association (the NT ~equivalent of shebang lines) set up as:

    assoc .pl=perl_script ftype perl_script=c:\perl\bin\perl.exe -w %1 %*

    Which means that your scripts probably were being invoked with -w.

    If you choose to use DirtyDamnApe's one-liner to update your CGI script shebang lines, it would make sense (from a security point of view) to make them -Tw to enable taint checking. (See perlman:perlsec)

Re: Don't want to have to use -w
by gav^ (Curate) on Jul 17, 2002 at 19:47 UTC
    I think you'll find it is a problem with line endings and if you upload the script in ASCII (if you are uploading with ftp) it will work fine.

Re: Don't want to have to use -w
by Benahimvp (Initiate) on Jul 17, 2002 at 22:05 UTC
    Thanks guys for your help. To reply to gav^, I created the file using the vi editor, so I don't see why there should be a problem with the line endings. Also, thank you, DamnDirtyApe, for the one-liner. If I already have some files with "-w" would it affect it (make it "-w -w"), or will it just not consider it?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2016-06-25 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (323 votes). Check out past polls.