I have written a script that will connect to my SQL 2k DB and pull a random image form a random table. All works well and fine execpt that at some point, and I am not sure where, $gallery gets propergated with 'ffxi' and screws everything up.
#!/user/bin/perl -w use CGI q~:standard~; use CGI::Carp qw(fatalsToBrowser); use strict; use DBI; print "Content-type: text/html\n\n"; my ($dbh, $sth, $haveimage, @games, @holder, $gallerynumber, $gallery, + @imghold, @images, $imagenumber, $image, $groupname, $test); $haveimage = 'No'; $dbh = DBI -> connect ('dbi:ODBC:read', 'uid', 'pass') or die "$DBI::e +rrstr;"; $sth = $dbh -> prepare (q~select table_name from FFImages.information_ +schema.tables where table_catalog = 'FFImages' and table_type = 'Base + Table' and table_name != 'dtproperties' and table_name != 'avatars'~ +) or die "$DBI::errstr;"; $sth -> execute() or die "$DBI::errstr;"; while (@holder = $sth -> fetchrow_array){ @games = (@games, @holder); } do { $gallerynumber = int(rand(@games)); $gallery = $games[$gallerynumber]; #There are 48 possible results +for $Gallery $sth = $dbh -> prepare (qq~select ImageName from FFImages.dbo.$gal +lery~) or die "$DBI::errstr;"; $sth -> execute() or die "$DBI::errstr;"; while (@imghold = $sth -> fetchrow_array){ @images = (@images, @imghold); } if ($images[0] ne ''){#Right now the only $gallery results that wo +uld return true here are 'ffac' and 'ffxi' $imagenumber = int(rand(@images)); $image = $images[$imagenumber]; $sth = $dbh -> prepare(qq~select GroupName from FFImages.dbo.$ +gallery where ImageName = '$image'~) or die "$DBI::errstr;"; #Everyth +ing is working fine up to and including this part, after here no matt +er what was in $gallery it is not longer there $sth -> execute() or die "$DBI::errstr;"; $groupname = $sth -> fetchrow_array; print qq~<img src="http://admin.ffinfo.com/cgi-bin/fileprotect +ion/fileprotection.pl/$image?file=images/$gallery/$groupname/$image" +style="max-height: 143px; max-width: 143px" alt="Random Final Fantasy + Image" />~; #At this point $gallery now contains 'ffxi' even if it d +id not before hand. $haveimage = 'Yes'; } } while ($haveimage ne 'Yes'); $dbh -> disconnect();
Can anyone tell me why $gallery is changed twords the end of the script when I never change it, at least I can not see it changing.

In reply to Where in the world is it getting 'ffxi' at? by Eagle_f90

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.