use strict; use warnings; my @outcome_tests = ( [ 97, 100, '99' ], [ 93, 97, '95' ], [ 85, 93, '90' ], [ 75, 85, '80' ], [ 65, 75, '70' ], [ 55, 65, '60' ], [ 45, 55, '50' ], [ 35, 45, '40' ], [ 25, 35, '30' ], [ 15, 25, '20' ], [ 7, 15, '10' ], [ 3, 7, '05' ], [ 0, 3, '00' ], ); for( 1 .. 20 ) { # Run the test 20 times. my $outcome = int( rand( 100 ) + 1 ); # Generate some test data. my $rv = ''; TEST: { foreach my $test ( @outcome_tests ) { my( $lower, $upper, $category ) = @{ $test }; if( $outcome > $lower and $outcome <= $upper ) { $rv .= $category; last TEST; } } die "ERROR: $outcome is out of bounds.\n"; } print "$outcome => $rv\n"; }