Richard Heintze wrote: > I have just discovered the the following code causes > trouble when I have "use strict" and "use warn"; > > use strict; > use warnings; > > my $k = $q->param('xyz'); > print qq[ \$k = $k ]; > > The problem is that if there is no GET/POST param > called xyz, we are concatenating with a null value > and, when using CGI with Apache HTTPD, this is not a > problem (except it tends to make for large error > logs). > > However, when using it with IIS it is a big problem > because the warning text gets inserted into the HTML > output (which is a BIG problem if you are in the > middle of emitting javascript code). > > Is there a way I can suppress only concatenation > warnings? I did perldoc strict and perldoc warnings > and could not determine if the supression I want is > possible.
Suppression only serves to hide problems rather than fix them. my $k = $q->param('xyz') || ""; This explicitly says (to the perl programmer): $k is set to the 'xyz' parameter from my query. However, if that parameter is false, use a blank string instead. This falls down if '0' is a valid value for the 'xyz' parameter. Better would be the // operator mentioned in the "future directions" document in perl 5.8.1. In the meantime, for complete accuracy where '0' is a valid value for your parameter, try: my $k = $q->param('xyz'); $k = '' unless defined $k; Again, this has almost the same explicit meaning: $k is set to the 'xyz' parameter from my query. However, if that parameter is undefined, use a blank string instead. Finally, you may want/need to preserve the undef nature of $k. Now you need to explicitly handle it in your concatentations: print q[ $k = ], (defined $k ? $k : q[<undef>]); Here I've used, as an example, the ability to tell the user that $k really was undef rather than blank. Of course $k really could have been '<undef>', but that's relatively unlikely in most circumstances. The key point to all of this is that you should be explicit with your undef handling. Masking the concatentation error message is the wrong solution if only because it will then hide real concatenation errors you may have elsewhere in your code. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]