## Read in all the images and numbers. There are probably ## not that many, so don't worry about the efficiency of it too much. @Images = &LoadImages(); ## Figure out which page it is coming from. For this example, ## let's say that each page (or even section of a page for ## multiple banners on one page (yuck!)) my $pagenumber = &GrabNumber(); ## Now just populate an hash of number strings. Since the page numbers ## are just simply sequential in this example, we could ## have used an array, but the hash lines up ## neatly and allows us to easily change page "34" later ## without counting lines, or worrying about order. ## Each pagenumber gets it's own grouping of images. my %imagegroup = ( 1 => "1,2,5,7", 2 => "2,4", 3 => "*", 4 => "1,2,3", 5 => "4,8,10", ); ## For the above, page "1" gets images one, two, five, and seven, etc... ## Note how pagenumber "3" is always going to get all images. ## Then just generate a random image. Again, because the ## list of images will probable be small, we don't worry ## too much about efficiency here (besides, it's early!) ## Default to "all images" my $grouping = $imagegroup{$pagenumber} || "*"; my $bail=0; { my $guess = int rand @Images; last if $grouping eq "*" or $bail++ > 1000; $grouping =~ /\b$guess\b/ or redo; } ## Now $Image[$guess] is the one to display...