!#/bin/perl print ""; $file = "table"; open(INFO, $file); @list = ; chomp(@list); close(INFO); print scalar @list; print @list; print "", binarySearch(\@list, "Lion"),"\n"; sub binarySearch { my ($list, $query) = @_; print "This is the search index for $query :\t" ; my ($low, $high) = (0, $#{$list}); #print "Low=",$low; #print "High=",$high; while ( $low <= $high ) { $temp = $low + $high; if(($temp)%2 == 0) { my $mid = int( $temp / 2 ); #print $list->[$mid]," "; #print $query,"!"; $list->[$mid] lt $query and do { $low = $mid + 1; next }; $list->[$mid] gt $query and do { $high = $mid - 1; next }; return $mid; # By this point it must be equal! } else { my $mid = int( ($temp - 1) / 2 ); #print $list->[$mid]," "; #print $query,"!"; $list->[$mid] lt $query and do { $low = $mid + 1; next }; $list->[$mid] gt $query and do { $high = $mid - 1; next }; return $mid; # By this point it must be equal! } } } ####End Of Code#### #*** INput File(Table) ***# Cat Dog Lion Monkey Zebra