I've been modifying a trivia game (originally written by someone else) for a few weeks. They used CGI.pm extensively, which irritates me to no end, but I wanted to work with it.

I wanted to keep track of which questions had not been asked yet. So, I decided to place this list of unasked questions in a hidden field (rather than a cookie, or a file on the server.) To my surprise, this list remained the same through every post, instead of updating as I had intended.

After reviewing the code several times, becoming increasingly frustrated each time, I determined my code was fine. So, I read the freaking manual. I had no idea that state was maintained with CGI.pm when you use the HTML generating functions to print out fields. And even when I first read that state was maintained, I didn't believe that it applied to my code.

So here are my questions:

  1. Why doesn't the manual tell me how to turn off this state-maintaining feature? Is there a way to do it?
  2. Why would anyone create a feature to maintain state that will not update the state of a field if new data is provided for that field? That's just anti-common-sense to me. The server I'm working on uses v1.49. Is there a newer version available that actually changes state if asked to?

As a note to anyone else that experiences this problem, there are two ways of eleviating the situation.

The first is to not use the CGI.pm function to create the field that has irritatingly consistent data. For example: the script was using hidden() to create a hidden field, and I simply used a print statement and wrote the HTML myself.

The second is to use delete() to delete the problematic field's data before you create the field again (e.g. $query->delete('hidden_field')).

Another way of fixing this would be to turn state-maintenance off, if possible.

# Dross, Professional Dullard

Edited 2001-08-04 by Ovid


In reply to CGI.pm: How to Stop Maintaining State by Dross

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.