#!/usr/bin/perl print "Content-type:text/html\n\n"; srand(time() ^ ($$ + ($$ << 15)) ); open(INF,"addata.txt"); @grok = ; close(INF); @vads = (); foreach $i (@grok) { # added this line in case the file has a blank line in it if ($i eq "") { next; # skip to the next loop iteration } chomp($i); ($id,$gif,$url,$alt,$max,$count) = split(/\|/,$i); if ($count < $max) { push(@vads,$i); } } $rid = int(rand(@vads)); if ($rid < 0) { # there's been some problem. Abort. exit; } $ad = $vads[$rid]; ($id,$gif,$url,$alt,$max,$count) = split(/\|/,$ad); print qq($alt\n); $count = $count + 1; open(INF,">addata.txt"); flock(INF,2); seek(INF,0,0); foreach $i (@grok) { chomp($i); if ($i eq $ad) { print INF "$id|$gif|$url|$alt|$max|$count\n"; } else { print INF "$i\n"; } } close(INF);