I think the error is being generated by the destructor ("in cleanup") of an object going out of scope; in this case $session is the only plausible candidate. You can test this hypothesis by taking the code back out of the sub and sticking it in its own block off the top level, like this:

{ my $sid = cookie('main') || undef; my @sessionInfo; my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/s +essions'}); if ( $session->is_new() ) { $session->delete(); } else { # get values from session } }
If the hypothesis is correct, this should also trigger the same error.

If this is case, then the hard part is figuring out why the destructor is having problems. As usual, I'd fire up the debugger (perldb) and start following stuff around. Or you may use the tried and true print-statement debugging method to probe the status of the object created by the constructor. Are you running with warnings? If not, turn them on, just in case the constructor is emitting warnings about problems when creating the new instance. In particular, does the server have permission to write to directory mentioned in the error message? Does the file mentioned in the error message still exist after the program exits? Can you log the contents of the directory in question before exiting the problematic block, to see if the constructor succeeded in creating the file that the destructor is failing to unlink?

Update: One thing I should have mentioned from the get go is that if the destructor hypothesis is correct (and ikegami's idea with the warn statement is clearly a simpler way to nail it than what I proposed above of moving the code to a block off the top level yadda-yadda), then you should look for a subroutine called DESTROY in CGI/Session.pm, and just look at what that subroutine is attempting to do (that's the beauty of open source!). That'll give some good clues for why you are getting the error.

the lowliest monk


In reply to Re: Code works fine, but in subroutine does not... help plz! by tlm
in thread Code works fine, but in subroutine does not... help plz! by Stenyj

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.