I've been working on some very strange behaviour with a very basic perl cgi script for a few days and something very strange is happening.
#!C:/perl/bin/perl -- use strict; use CGI qw/ :standard /; use CGI::Cookie; use CGI::Carp qw/ fatalsToBrowser /; use CGI::Session; my $q = new CGI; my $session = new CGI::Session("driver:File", $q->cookie('CGISESSID') || $q->param('CGISESSID') || und +ef, { Directory => 'C:/temp/test/area' } ) or die ($CGI::Session::errstr); my $session_id = $session->id(); print $session->header; print $q->start_html(-title=>"www\.test\.com");#, $q->Dump, $q->query_ +string; my $in=$session->param('loggedin'); print "in = ", ((defined $in) ? $in : "UNDEFINED"); my $count = $session->param("loggedin") || "1"; $session->param( "loggedin", ($count+1) ); print $q->end_html; sub not_called { my($count); print "hello - i am never called !"; #$count=$session->param( "loggedin"); <<<<< PROBLEM }
The basic script simply sets up a cookie and then simply increments a counter for the duration of the session.

The line marked as '<<<<< PROBLEM' is giving me the problem. It's in a function which is never called. When the line is commented out the script works ok. When the line is uncommented I get a problem. The problem seems to be that CGI::session is no longer interested in saving anything to disk ( ie in the /temp/test/area area ). There is no session management occuring so session->id is different every time. Comment out the line and everything works well. I can't say how weird this is !!!! why a line which is never called could affect the program is beyond me.

Perl is v5.8.6 on windows. Web Server is Apache.

I'm really stuck here and this is the weirdest problem I've seen in all my days of using perl !

PS - just so we're clear the '<<<<< PROBLEM' label was added after the code was pasted to perlmonks. I am not trying to run the script with that in place ;-)


In reply to very strange problem with CGI::Session by wertert

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.