Simple style question.
I have a count variable that is to be set depending on a condition:
Wherein '$some_variable' can have the values 'x' and 'y' only.if ($some_variable eq 'x') { $count = 14; } else { $count = 9; } for $i (0 .. $count) { do some stuff }
Setting two value holders at the top of the script make for easier maintenance when the values need to be changed some day:
but it creates double referencing and extra lines of code.#constant declaration area at top of script $value_1 = 14; $value_2 = 9; ...many lines of code later... if ($some_variable eq 'x') { $count = $value_1; } else { $count = $value_2; } for $i (0 .. $count) { do some stuff }
A third way would be to declare a hash:
Any feelings on which is preferable from a coding style and/or efficiency point of view?#constant declaration area at top of script $count{'x'} = 14; $count{'y'} = 9; ...many lines of code later... for $i (0 .. $count{$some_variable}) { do some stuff }
Forget that fear of gravity,
Get a little savagery in your life.
In reply to Style: buried variables or double referencing? by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |