Gurus,

I've fiddled with this table and so far a reasonable, or at least pretty, solution's evaded me. Given the values of the first two columns as inputs, I need the column number specified in the third as my output. Note that there's an oddball value for $letter in row number 11--this is what's throwing me the curve. I've got a lumpy looking chunk of code that does it, but I'd prefer something cleaner... Any ideas?

$num $letter $col
1 A 1
1 B 2
2 A 3
2 B 4
3 A 5
3 B 6
4 A 7
4 B 8
5 A 9
5 B 10
5 C 11
6 A 12
6 B 13



My lumpy code:

if (($num < 6) && ($letter ne 'C')) {
   $x = ($letter eq 'B' ? 0 : 1;
   $col = ($num * 2) - $x;
}
elsif ($num == 5) {
   $col = 11;
}
else {
   $x = ($letter eq 'B') ? 1 : 0;
   $col = 12 + $x;
}

Can anyone suggest a prettier alternative?

Thanks,

Deane
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to