Keep It Simple, Stupid | |
PerlMonks |
Re: Bad Code?by Foggy Bottoms (Monk) |
on Aug 19, 2003 at 14:36 UTC ( [id://284911]=note: print w/replies, xml ) | Need Help?? |
I read your code and it seems fine, not that I'd be able to discern between appallingly awful code and tremendously great code... There are however a couple changes I'd make : first off, I'd use the pragma use strict; at the very beginning of your code - it then forces you to declare your variables the following way : my $a; or my $a = 17;... It prevents you from mixing up eponymous variables specially when you go into loops. Second of all, before even testing the number, I'd initialize ask for it... : Hence the if (defined $guess is useless and you can directly write : my $answer = ($guess>$secret_number?("bigger than"):($guess<$secret_number?("smaller than"):"")) I note that you've used eq : this is a string comparison tool. It's best you use == (as in C). On second thoughts, I've noticed you're using eq because of $guess = <STDIN> in which case you're right eq is better... Lastly, instead of using $quit as a string which then makes you use regexes, you'd be better off using a byte : $quit = 1; or even a constant : $quit = YES provided you previouslt declared YES : use constant YES => 1... Hope this helps...
In Section
Seekers of Perl Wisdom
|
|