Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

unwanted error messages appearing :-)

by LaidBackWebSage (Acolyte)
on Feb 25, 2004 at 18:22 UTC ( #331757=perlquestion: print w/ replies, xml ) Need Help??
LaidBackWebSage has asked for the wisdom of the Perl Monks concerning the following question:

This is a weird situation... I have three Solaris servers, all configured with the same Apache version, same conf file, same mod_perl, etc. These servers are, respectively, dev, test, and prod. Running the same script on all three servers, I only get error messagess on the dev server; the error messages look like this: Use of uninitialized value in concatenation (.) or string at <script> Line ### The "error" is occurring because of code like the following:
print qq^ <input type="text" class="classDef" name="elementName" size="25" v +alue="$HASH{ key }"> ^;
Where the "$HASH{ key }" has not been defined (since the instance is being used to do an insert into the database, not an update). The question has two parts: 1) Why are these errors being generated to the Apache error log on the dev server but not the other two servers? 2) How do I make it stop? <sob> Thanks for any and all assistance! Kevin Jackson

Comment on unwanted error messages appearing :-)
Download Code
Re: unwanted error messages appearing :-)
by b10m (Vicar) on Feb 25, 2004 at 18:42 UTC

    It's hard to believe that all three scripts and servers are identical, when one of them is giving a warning, and the other two do not. Therefore I strongly believe that the script on the dev-server uses `perl -w`, while the others do not :) Perl doesn't warn you just because it likes to do so, so much, but rather to inform you that your code isn't what it should be. To make it go away? Make sure $HASH{key} contains a value (or don't use it), or delete the "-w" from the hashbang ;)

    Update: besides the hashbang, the warnings can be turned on using use warnings; and maybe your sysadmin created an alias for perl (alias perl='perl -w'). Who knows? Would make sense on a dev. machine.

    --
    b10m

    All code is usually tested, but rarely trusted.
Re: unwanted error messages appearing :-)
by dws (Chancellor) on Feb 25, 2004 at 18:51 UTC
    1) Why are these errors being generated to the Apache error log on the dev server but not the other two servers?
    2) How do I make it stop?

    The easy way to make it stop is to add

    $HASH{key} ||= "";
    before the print. But that doesn't get you closer to a root cause.

    Assuming that you've verified that the scripts really are identical, you might look to see that if the scripts do

    use warnings;
    If so, verify that warnings.pm is identical on each server. It's kind of a long shot, but someone may have tweaked on of them to "get rid" of a similar problem. It's an evil thing to do, but I've worked with some evil people, so it may be worth checking.

Re: unwanted error messages appearing :-) (fix the cause, not the symptom)
by grinder (Bishop) on Feb 25, 2004 at 19:05 UTC
    since the instance is being used to do an insert into the database, not an update

    Do you mean that in the dev environment you're doing an insert, but on the test and prod environments you're doing updates? I'm a little unclear on the concept. Shouldn't the code handle both scenarios?

    I would not worry so much about the warning, it's doing its job: telling you something odd is happening. I would instead concentrate on the program logic and trace back to where $HASH{key} is being set, or more importantly, why it's not. Don't shoot the messenger.

    And set my mind at ease, tell you you don't really have a hash variable in your code named HASH? There are surely better names that would do?

Re: unwanted error messages appearing :-)
by LaidBackWebSage (Acolyte) on Feb 25, 2004 at 20:17 UTC

    I found the cause and the solution. (Yay, me!)

    While debugging the script, I used the "use warnings" and "use diagnostics" pragmas. Later on I took them out of the code, but they remained latent in mod_perl, which is why the appearance of the error messages confused me.

    I restarted the Apache server and voila! same script, no more error messages.

    Do I get extra points for solving my own problem? :-)

      Do I get extra points for solving my own problem?

      Yes, you do. But the true solution to your problem is to clean up the code to eliminate the warnings, rather than just hiding them. What you did is referred to as treating the symptom, rather than fixing the cause. Previous posts have given you clues how to fix the cause of the warnings; I would suggest following their advice. 8^)

      Do I get extra points for solving my own problem? :-)

      No, because monks have put time in reading your problem, suggesting possible sollutions (and hey, you had two "right" answers before you solved this "yourself") and because you have lied: "Running the same script on all three servers" So no, no points for you ;)

      --
      b10m

      All code is usually tested, but rarely trusted.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-10-22 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (118 votes), past polls