if (exists $USER{coffee} && $USER{coffee} > 5){$msg='You drink too muc +h coffee'}
It checks that the coffee key exists in %USER. You can just use
It will get rid of the warning, but won't actually do anything useful. exists checks that the coffee key was created. This check actually tells you a potentially relevant piece of information. e.gif ($USER{coffee} && $USER{coffee} > 5){$msg='You drink too much coffe +e'}
There is no point in adding code just to get rid of a warning if the new code does nothing useful! It is a poor practice to get into and can be confusing to the people that have to maintain you application. Like Abigail said check your input to make sure no one made a mistake inputting a value (or is pulling a fast one on you).if (! exists $USER{coffee}){ $msg = 'You drank no coffee?!?!'; } elsif ($USER{coffee} > 5){ $msg='You drink too much coffee'; } else { $msg='You drank a moderate amount of coffee'; }
This doesn't seem to be the behaviour that you want.
HTH,
Clayton
Update:
I removed a section that said testing if a non exsistant key was defined would autovivify it and added my support for Abigail's answer. I swear with God as my witness...
In reply to Re: -w in production environment
by clscott
in thread -w in production environment
by gwhite
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |