How about something like:
# default $Max_Questions = $Total_Questions unless defined $Max_Questions; # check boundaries croak "Number of questions in $FileName exceeded" if $Max_Questions > $Total_Questions; croak "Must have at least one question in the test" if $Max_Questions < 1; # good to go &_set_Max_Questions($self, $Max_Questions);
Update: D'oh! Corion beat me to it... but I like croak ... if better than if ... croak in this case; I think it makes it more obvious that the boundary checks are error conditions, rather than correctable "mistakes" (like undefined $Max_Questions).
Update 2: Fixed syntax error... thanks TStanley.
--
The hell with paco, vote for Erudil!
:wq
In reply to Re: Optimization of a piece of code(Is there a better way than this?)
by FoxtrotUniform
in thread Optimization of a piece of code(Is there a better way than this?)
by TStanley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |