warnings or -w ?

Y

Yohan N Leder

Hello,

What the preferable way to activate warnings in CGI Perl scripts ? And,
especially, why ?

1) The "-w" in the shebang line as "#!/usr/bin/perl -w"
2) Or a "use warnings;"

This question because, I'm used to use "use warnings", but was surprised
to see, some days ago, that some servers (for example, in a Fedora Core
5 with httpd and the Perl packages installed by default) don't have this
module and fail on it with errors log saying something like "no such a
file".
 
S

Sisyphus

Yohan N Leder said:
Hello,

What the preferable way to activate warnings in CGI Perl scripts ? And,
especially, why ?

1) The "-w" in the shebang line as "#!/usr/bin/perl -w"
2) Or a "use warnings;"

See 'perldoc perllexwarn'.
I think the short answer is "use warnings, unless the warnings module is not
available".
This question because, I'm used to use "use warnings", but was surprised
to see, some days ago, that some servers (for example, in a Fedora Core
5 with httpd and the Perl packages installed by default) don't have this
module and fail on it with errors log saying something like "no such a
file".

I don't think the warnings module became available until perl-5.6.
Any servers running earlier versions of perl will therefore throw up the
error you describe.

Cheers,
Rob
 
P

Peter J. Holzer

This question because, I'm used to use "use warnings", but was surprised
to see, some days ago, that some servers (for example, in a Fedora Core
5 with httpd and the Perl packages installed by default) don't have this
module

I don't believe this. Fortunately I have a Fedora 5 box to check:

wifo715:~ 15:06 101% cat /etc/redhat-release
Fedora Core release 5 (Bordeaux)
wifo715:~ 15:06 102% perl -Mwarnings -e 42
Useless use of a constant in void context at -e line 1.

Seems to be there

wifo715:~ 15:07 104% perldoc -l warnings
/usr/lib/perl5/5.8.8/warnings.pm
wifo715:~ 15:07 105% rpm -qf /usr/lib/perl5/5.8.8/warnings.pm
perl-5.8.8-5

and it's in the base package. If you find a Fedora 5 which has perl
installed but no warnings.pm, it either isn't Fedora's perl package or
somebody has manually deleted part of the package.

hp
 
T

Tad McClellan

Yohan N Leder said:
What the preferable way to activate warnings in CGI Perl scripts ?


[ Using Perl in a CGI environment has no bearing on which one is preferred.

But if you _are_ using Perl in a CGI environment, then:

perldoc -q CGI

How can I get better error messages from a CGI program?
]


That can be answered by

perldoc warnings

The "warnings" pragma is a replacement for the command line flag "−w",
And,
especially, why ?


That is the next line of the docs quoted above:

but the pragma is limited to the enclosing block, while the flag is
global. See perllexwarn for more information.

1) The "-w" in the shebang line as "#!/usr/bin/perl -w"
2) Or a "use warnings;"

This question because, I'm used to use "use warnings",


Good. Keep doing that.

but was surprised
to see, some days ago, that some servers (for example, in a Fedora Core
5 with httpd and the Perl packages installed by default) don't have this
module


Then they likely have a really really old version of perl.

Lexical warnings (ie. use warnings) have been part of Perl
for many years.

and fail on it with errors log saying something like


"something like" is worthless when dealing with computers. Exact
details matter when dealing with machines.

Please quote the exact text of the message.

Have you seen the Posting Guidelines that are posted here frequently?
 
M

Martijn Lievaart

I don't think the warnings module became available until perl-5.6.
Any servers running earlier versions of perl will therefore throw up the
error you describe.

Even Fedora Core 1 comes with this module (Perl 5.8.3).

M4
 
Y

Yohan N Leder

I don't believe this. Fortunately I have a Fedora 5 box to check:

wifo715:~ 15:06 101% cat /etc/redhat-release
Fedora Core release 5 (Bordeaux)
wifo715:~ 15:06 102% perl -Mwarnings -e 42
Useless use of a constant in void context at -e line 1.

Seems to be there

wifo715:~ 15:07 104% perldoc -l warnings
/usr/lib/perl5/5.8.8/warnings.pm
wifo715:~ 15:07 105% rpm -qf /usr/lib/perl5/5.8.8/warnings.pm
perl-5.8.8-5

Your right, I've a FC5 box too in the LAN and I'm getting the same
result :

root@localhost ~]# cat /etc/redhat-release
Fedora Core release 5 (Bordeaux)
[root@localhost ~]# perl -Mwarnings -e 42
Useless use of a constant in void context at -e line 1.
[root@localhost ~]# perldoc -l warnings
/usr/lib/perl5/5.8.8/warnings.pm
[root@localhost ~]# rpm -qf /usr/lib/perl5/5.8.8/warnings.pm
perl-5.8.8-5
[root@localhost ~]#

However, this server was a one in several and it's always possible
someone (a joker admin) modify something on the others.

Well, I have to check on a simple cgi with -w on a side and use warning
on another to see if it's at least ok on this FC5 in Perl 5.8.8 and
warnings.pm presents...
 
Y

Yohan N Leder

sisyphus1 said:
See 'perldoc perllexwarn'.
I think the short answer is "use warnings, unless the warnings module is not
available".

OK, noted, thanks !
I don't think the warnings module became available until perl-5.6.
Any servers running earlier versions of perl will therefore throw up the
error you describe.

The FC5 comes with Perl 5.8 and I've checked warnings package is
presents from the Sisyphus's post. So, the problem is elsewhere (why
does the use warnings seems to fails ; I've to do some checking and will
be back soon)
 
Y

Yohan N Leder

Then they likely have a really really old version of perl.
Lexical warnings (ie. use warnings) have been part of Perl
for many years.

From the Sisyphus reply in this thread, I've checked on a FC5 server on
which I've access (not the only one, but a one on which the problem
occured) and there is Perl 5.8.8... So, the problem comes from something
else than absence of warnings module.
"something like" is worthless when dealing with computers. Exact
details matter when dealing with machines.

Please quote the exact text of the message.

Have you seen the Posting Guidelines that are posted here frequently?

Not necessary to be agressive unless you spent a bad day :)

Well, now, knowing it's close to be sure (based on the FC5 I've in the
LAN which may be different than others on which I've seen same problem)
it's not a matter of absence of warnings.pm, I've reduced problem
through two short cgi scripts :

1) This first one using "-w" works fine (string printed in browser)
#!/usr/bin/perl -w
use strict;
print "Content-type: text/html\n\n";
print "<HTML>";
print "<BODY>";
print "<P>Bonjour le monde !</P>";
print "</BODY>";
print "</HTML>";
exit 0;


2) This second one using warnings module doesn't works (browser empty)
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/html\n\n";
print "<HTML>";
print "<BODY>";
print "<P>Bonjour le monde !</P>";
print "</BODY>";
print "</HTML>";
exit 0;

And the error log of httpd says :
[Sun Nov 05 21:30:25 2006] [error] [client 127.0.0.1] (2)No such file or
directory: exec of '/var/www/cgi-bin/bonjour.pl' failed, referer:
http://localhost/
[Sun Nov 05 21:30:25 2006] [error] [client 127.0.0.1] Premature end of
script headers: bonjour.pl, referer: http://localhost/

Notice that I've ran this test from a browser in the server itself here
; tomorrow, I'll do it from another station.
 
P

Peter J. Holzer

it's not a matter of absence of warnings.pm, I've reduced problem
through two short cgi scripts :

1) This first one using "-w" works fine (string printed in browser)
#!/usr/bin/perl -w
use strict; [...]


2) This second one using warnings module doesn't works (browser empty)
#!/usr/bin/perl
use strict;
use warnings; [...]

And the error log of httpd says :
[Sun Nov 05 21:30:25 2006] [error] [client 127.0.0.1] (2)No such file or
directory: exec of '/var/www/cgi-bin/bonjour.pl' failed, referer:
http://localhost/

My crystal ball says you should check your line endings.

hp
 
T

Tad McClellan

Yohan N Leder said:
The FC5 comes with Perl 5.8 and I've checked warnings package is
presents from the Sisyphus's post. So, the problem is elsewhere (why
does the use warnings seems to fails ; I've to do some checking and will
be back soon)


One thing to check that has bitten me more than once in the past:

If you leave the semicolon off of the end of the "use warnings",
then you get messages that seem to come from the Twilight Zone...
 
T

Tad McClellan

Yohan N Leder said:
the problem comes from something
else than absence of warnings module.


And we would have known that, had we been privileged with
the exact text of the error message!



Well, have you?

Not necessary to be agressive unless you spent a bad day :)


There is not anything agressive in what I wrote (above).

I wasted time guessing the wrong thing because you didn't give
the message text.

You wasted your time because you didn't get the right answer.

Posting the message text helps you and helps everybody else
here too.


Now here is something that _is_ aggressive:

*plonk*
 
Y

Yohan N Leder

He wasn't being agressive, just giving good advice.

Not sure... In this thread Sisyphus and you gave me good advice (see
below) !
I am assuming you are FTP'in these scripts to the FC5 server from a
Windows computer. In that case, make sure they are transferred in ASCII
mode.

In fact, no : my own stations are one under Windows and the second under
Ubuntu ; however, it's a fact I generally write a first release under
Win, then transfert to Ubuntu for testing and final upload toward
servers. And, in rare case, I ftp upload from Win, ascii mode is well
asociated with .pl extension.
Your problem very likely has absolutely nothing to do with the warnings
module, but with the presence of options on the shebang line. For
example, I am guessing that

#!/usr/bin/perl --

You're absolutely right here ! So, I've searched what could be wrong in
the "scripts with problem"... Well, the fact is that, here, every
developer send his work to all other developers for final check and (it
was difficult to figure out)... And the Linux servers on which problem
occured were, all, managed or co-managed by a single man who recently
installed a different Komodo release for his own usage. The problem is
that in these Komodo settings, he (surely not volontarily because it has
not any sense) checked "preserve existing line ending" as "\r\n". So,
even if file were correctly ftp uploaded (with line ending conversion),
this simple checkbox does every scripts which have been re-edited
locally in these Komodo has been changed back with Win style \r\n.

Fortunately this has no influence on final end-user servers because,
after checking and approval of all developers (who report their opinion
back to original developper), the scripts which are finally released are
the one (modified or not) from original plateform.

I've changed by myself this Komodo settings on the FC5 server and
propagated the things toward team for local checking. Solved ! Thanks
 
Y

Yohan N Leder

One thing to check that has bitten me more than once in the past:

If you leave the semicolon off of the end of the "use warnings",
then you get messages that seem to come from the Twilight Zone...

Solved now (see A. Sinan Unur post and subsequent one), it was a matter
og Komodo settings on this (I hope 'these') server(s).

Thanks anyway
 
T

Tad McClellan

A. Sinan Unur said:
[...] *plonk*

Your post is totally unuseful, Tad. So, sorry to *double-plonk* at my
turn... [second degree for those who has not access to it]

I see your plonk and raise you triple.


Perhaps the OP can _now_ see the usefulness of my reply.

The points made are (errr, would have been ) useful for avoiding earning
a killfile entry.
 
C

Chris G.

Thanks for the discussion. I never gave it any thought of how to
implement the "warnings" before. Thanks for the discussion of why I
should do the "use warnings" vs "-w".

Chris G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top