Gurus,
I've got a sub that uses a pseudo-switch for "loop" to assign values to its return variable based on the value of its passed in arguments. The sub is called from a loop and each possible value of the selector variable, $row, is guaranteed to be hit once and only once. The values run from zero through 93.
The puzzle I have is this: do I have the best ordering of the selections in terms of minimizing the number of tests to go through over the life of the calling loop? I did find one change that decreased the total of tests by almost 20, and this led me to pondering whether I could cut the test count even further by some rearrangement of the selections. Any suggestions? I've thought of testthis/testthese, but which such a haystack of possible arrangements, that seemed like WAY too much searching for the (admittedly insignificant) needle--not quite worth the candle.
I'm hoping someone's worked with something like this and can share his/her experience with me.
Here's the code:
sub translate_reg_value
{
my ($row, $regval) = @_;
my $out = q{};
for ($row) {
/^(?:5|6|19|20|21|22|35|36|37|41|42|43|49|50|53|55|56|57|59|60|65|66|67|68|69|71|73|83)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:11|12|13|14|18|24|28|40|48|51|52|54|61|62|63|64|70|72|78|80|82|84|86|87|91|92|93)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:0|2|7|8|9|23|27)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:38|39|45|46|47|79|85)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:29|30|31|32|33|34)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:74|75|76|77)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:88|89|90)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:25|26)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:1)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:3)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:4)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:10)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:15)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:44)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:58)$/o && do {
# do something to $out involving $regval
last;
};
/^(?:81)$/o && do {
# do something to $out involving $regval
last;
};
} # end for ($row)
return( $out );
}
Thanks!
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"Truth is eternal, knowledge is changeable. It is disastrous to confuse them." -- Madeleine L'Engle
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
