in reply to Critique
#hash slice with a range my %months; @months{1..12} = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
You could write your "get_days()" function like this:
sub get_days { my $month = shift; return 31 if grep { $month eq $_ } qw/1 3 5 7 8 10 12/; return 30 if grep { $month eq $_ } qw/4 6 9 11/; return 29 if $month eq '2'; die "Bad month entered!\n"; }
This method eliminates the use of global variables that intentionally leak into functions.
For more speed-efficient lookup tables hashes are preferable, but these are small lists, and you're probably not checking thousands of times a second, so grep is probably fine. Not sure why I chose to treat month numbers as strings. I guess because I usually think of hash keys as strings too.
Those are the biggest changes I can think of, and they're really not necessary. Just look at them as "Another Way To Do It"
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Critique
by phenom (Chaplain) on Dec 06, 2003 at 14:43 UTC |