http://www.perlmonks.org?node_id=8830


in reply to Random Image in HTML

My quick version:
if (opendir(PIZZA, "$dirname")) { @images = grep { -f "$dirname/$_" && m/\.gif|jpg|png/ } readdir(PIZZ +A); srand(); $image = $images[rand($#images+1)]; closedir(PIZZA); if (open(IMAGE, "$dirname/$image")) { $size = -s IMAGE; printf "Content-length: %d\n", -s IMAGE; printf "Content-type: image/%s\n\n", substr($image,-3); while (<IMAGE>) { print; } close(IMAGE); } closedir(PIZZA); } exit;