damian has asked for the wisdom of the Perl Monks concerning the following question:

hi fellas, im a newbie in the world of PERL, i've created a script that randomizes the ads on my HTML.... the script is ran with a tag my problem now is how will i be able to track how many times the image was displayed. here is my code:
if(!open DAT, "ads.dat") { print "Error: cannot open data file!\n"; exit 1; } else { @imgdata=<DAT>; close DAT; foreach $c (@imgdata) { ($id,$image,$url,$from,$to,$type,$numshow,$numclicks,$desc)=split( +/\|/,$c); if ($type=~/^internal|partner$/) { push (@imgs,$image); push (@urls,$url); } } $img = $imgs[int(rand($#imgs+1))]; $link = $urls[int(rand($#urls+1))]; print qq|Set-Cookie: URL=$link\n|; print qq|Location: $img\n\n|; } }
any suggestions? forgive me for being so lame, i'm a newbie. thanks in advance.

Replies are listed 'Best First'.
RE: Tracking images printed on HTML
by chromatic (Archbishop) on Sep 14, 2000 at 07:31 UTC
    You already have the image that's being displayed for this invocation, so you have many options:
    • Update a key in a tied hash with the file name as a key
    • Append it to a logfile and let another script parse it
    • Use a full-blown database
    • Open a file named the same as the image, read a number from it, add one, and rewrite the file
    I've listed those in my preferred order. There are many good options.
Re: Tracking images printed on HTML
by jptxs (Curate) on Sep 14, 2000 at 09:30 UTC

    I would try the tied hash as chromatic suggests.
    If you are anywhere near the newbie I was just an infinitely short time ago, you can get info on these by:

    Using the tied hash will let you do all sorts of neat stuff like print reports pretty easily, and even start varying the images by how nuch they've been seen, etc.

    -- I'm a solipsist, and so is everyone else. (think about it)

Re: Tracking images printed on HTML
by little (Curate) on Sep 14, 2000 at 13:40 UTC
    you might use something like:
    push (@ids,$id); ... $mycounter[$id] += 1;
    after randomly having choosen an $img with referring $id, so you get an array with the $id of the $image as number of element and the number of views as values.
    update
    seem's it was alreday suggested - :-)
Re: Tracking images printed on HTML
by Anonymous Monk on Sep 15, 2000 at 01:57 UTC
    If you are using IIS or most other web servers then your log file will tell you how often the image is retrieved, and who retrieved it. All you need to do is grep the logfile for the name of the image.