I have a script that generates a page of identical images and when writing out the page, assigns a unique ID to each graphic based on a flat file. All of that works fine except for one thing..... Some of the ID fields will be empty. There doesn't seem to be any pattern to it as to length, specific ones, etc.

The flat file looks kinda like this:
FileName:GraphicName:Keywords
Example; AceSpades:Ace of Spades:Ace, Spades, Black, High card.......

In this instance, I am only using FileName. If I haven't completely confused everyone, any suggestions are appreciated. :-) If I have confused everyone, drop me a note and I will try to be more clear......

An example of the output is:

<DIV CLASS="Location1_1"> <IMG SRC="../tiles/thumbs/backside.jpg" id="Dagaz" onClick="trackClick +s(this)"> </DIV> <DIV CLASS="Location1_2"> <IMG SRC="../tiles/thumbs/backside.jpg" id="" onClick="trackClicks(thi +s)"> </DIV>
The first example is what should be displayed, the second is what I sometimes get.... The script is below.

#!e:\perl\perl.exe use CGI; use warnings; use Tie::File; use List::Util qw(shuffle); $query = CGI::new(); $Spread = $query->param("Spread"); $i=0; @place2 = qw(0 1_1 1_2 1_3 1_4 1_5 1_6 2_1 2_2 2_3 2_4 2_5 2_6 3_1 3_2 + 3_3 3_4 3_5 3_6 4_1 4_2 4_3 4_4 4_5 4_6); open(FILE,"< tiles.txt") or die "error opening tiles.txt $!"; tie @text, 'Tie::File', 'tiles.txt' or die $!; @text = shuffle(@text); while (<FILE>) { ($File[$i++], $Name[$i++], $Keywords[$i++]) = split(/:/; chomp ($Keywords[$i]); } close(FILE); print "content-type:text/html\n\n"; print "<HTML>\n<HEAD>\n"; print "<style type=\"text/css\">\n<!--\n"; print "\@import url(\"../styles.css\");\n//-->\n"; print "</style>\n\n"; print "<script type=\"text/javascript\">\n"; print "var max = $Count;\n"; print "function trackClicks(img) {\n"; print "self.c = self.c?c:0;\n"; print "self.cache = self.cache?cache:[];\n"; print "var found = false;\n"; print "for (var x = 0; x < cache.length; x++) {\n"; print "if (cache[x] == img.id) found = true;\n"; print "}\n"; print "if (!found) {\n"; print "cache.push(img.id);\n"; print "c++;\n"; print "}\n"; print "if (c >= max) {\n"; print "alert(cache)\n"; print "document.Selections.Cache.value=cache\n"; print "document.forms[0].submit();\n"; print "}\n"; print "}\n"; print "</script>\n"; print "</HEAD>\n"; print "<body>\n"; print "<DIV CLASS=\"MainWindow\">\n"; print "Test Layout<P>\n"; print "<DIV CLASS=\"MainContent\">\n"; print "<FORM NAME=\"Selections\" action=\"ShowLayout.pl\" method=\"POS +T\">\n"; for ($z=1; $z<=24; $z++) { print "<DIV CLASS=\"Location$place2[$z]\">\n"; print "<IMG SRC=\"../tiles/thumbs/backside.jpg\" id=\"$File[$z]\" onCl +ick=\"trackClicks(this)\">\n"; print "</DIV>\n"; } print "<Input type=\"hidden\" Name=\"Stones\" Value=\"$Stones\">\n"; print "<Input type=\"hidden\" Name=\"Cache\" Value=\"cache\">\n"; print "</FORM>\n";

In reply to Code not showing properly by JimJx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.