Your problem most likely is that you're using several CGI::Session objects in one run of the program. Every time you do

my $session = CGI::Session->load($sessionid);

a new session object (but not a new session/ID) is created, which will autoflush its data when it goes out of scope. If you maintain several CGI::Session objects (and thus separate in-memory representations of the session data) in one run of the program, the one that goes out of scope last will "win", as it overwrites (on-disk) any changes that may have been flushed before...

Your $session object that you created in between the "MARKING" comments is file-scope and will thus not go out of scope before the CGI terminates. The other one created within AddMessage() will go out of scope at the end of the subroutine. In other words, the file-scoped one wins, as it writes to disk later.

Try putting an explicit $session->flush() after "MARKING 3", or put an extra { ... } block around the "MARKING" section, and you should see different behaviour, i.e. in this case, the stuff added in AddMessage() will be flushed later.


In reply to Re: need serious help with CGI::Session by almut
in thread need serious help with CGI::Session by adrive

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.