in reply to Testing for 16 possible combinations with 4 pull-down menus

I don't understand why you are using pulldowns with only one valid item in each. So I am assuming you are doing preprocessing we don't know about.

Binary isn't normally good for scheduling (I've done a bunch with pulldowns recently) because what if you want to add quarter-hour resolution, etc. Anyway, assuming we have to deal with this binary code and you have it nicely padded so it is always 4 digits. So we have yummy binary! This says to me:

Valid states:
0000 0
1000 8
1010 10
1100 12
1111 15

So I parsed the binary and broke it into bits. Intentionally left no comments so you can learn from it in case this is homework. As for bounds checking, if you only need to check time0 < time1 then why not convert hours to minutes? (Not done here)

#!/usr/bin/perl -w use strict; my $str; my @test = ("0000","0001","0010","0011", "0100","0101","0110","0111", "1000","1001","1010","1011", "1100","1101","1110","1111"); my @accepted = (0,8,10,12,15); for my $t (@test) { print "Input: $t\tTested: "; print "[" . parsebin($t) . "] " ; print validinput($t,\@accepted); print "\n"; } sub validinput { my $in = shift; my $r = shift; return 1 if xinset(parsebin($in),$r); return 0; } sub xinset { my $x = shift; my $set = shift; #print "X $x SET" . join(" / ",@$set). "\n"; for my $y (@$set) { return 1 if $x == $y; } return 0; } sub parsebin { # parse a string of ones and zeroes my $str = shift; my $total = 0; my $power = 0; for my $i (1..length($str)) { $total += 2 ** $power if substr($str,-1 * $i,1); $power++; } return $total; }