in reply to Coding styles using if/else
my $name = param('name'); if (defined $name && length $name) { # I prefer to test for the pass case rather than the fail. print "Thank you, $name, your submission is complete.\n"; } else { print "Sorry, name can't be empty.\n"; } exit;
Your two examples and mine are all functionally equivalent, so it's just a matter of how the author likes to see things done. No worries.
Edit for clarity: I also tend to minimize the use of exit and/or die whenever possible, which is why I included the else in my example. I use length in case the user's name is 0e0 or some such nonsense.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Coding styles using if/else
by grinder (Bishop) on Apr 06, 2007 at 11:41 UTC | |
by talexb (Chancellor) on Apr 06, 2007 at 17:23 UTC | |
by jdporter (Paladin) on Apr 06, 2007 at 18:27 UTC | |
by kyle (Abbot) on Apr 06, 2007 at 18:01 UTC | |
Re^2: Coding styles using if/else
by dewey (Pilgrim) on Apr 06, 2007 at 05:35 UTC |