Hello, Sorry if I'm missing the obvious (yes I'm a newbie) but I've got a simple little cgi script that works flawlessly from the command line but has problems working from the web. It is just supposed to load different background images on each visit. When I run it from the web the bg.cnt file with just counts from 0 to 3 doesn't get written to properly and ends up with nothing in it. The permissions seem ok, with rw-rw-rw on the counting file. Thanks for any help anyone can provide.
#!/usr/bin/perl open IN, "<bg.cnt" or die "can't open bg.cnt"; flock(IN,2); seek(IN,0,0); $cnt=<IN>; close IN; if ($cnt >= 3){ $cnt = 0; } else { $cnt = $cnt + 1; } open OUT, ">bg.cnt" or die "can't open bg.cnt for writing"; flock (OUT, 2); seek(OUT,0,2); print OUT "$cnt \n"; close OUT; @background=("corner.jgp","anduin.jpg","gandalf.jpg","ford.jpg"); print "Content-type: text/html\n\n"; print <<EndOfHTML; <td background="images/$background[$cnt]"> EndOfHTML

In reply to writing to a file in a cgi script by sidhartha

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.