I have a really weird problem that stemmed from the solution to the problem found here:
CGI::Session - non-stop session creation problem
my $sid = cookie('main') || undef;
my @sessionInfo;
my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/ses
+sions'});
if ( $session->is_new() ) {
$session->delete();
} else {
# get values from session
}
This code grabs the SID from the cookie (previously stored when the user logged in), and then attempts to validate the session. If the user IS logged in, then it gets the values from the session, if the user is NOT logged in, then it destroys the session (as there's no need for it).
When I use the code above in the body of the script, it runs without errors being generated
BUT
when I put it into a subroutine, ie:
&test;
sub test {
my $sid = cookie('main') || undef;
my @sessionInfo;
my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache
+/sessions'});
if ( $session->is_new() ) {
$session->delete();
}
}
it returns the following error:
"Content-Type: text/html; charset=ISO-8859-1 (in cleanup) could not fl
+ush: Couldn't unlink C:\apache\sessions\cgisess_16a6fc56d547a55cb4ec0
+5c183c5c10b: No such file or directory at /apache/htdocs/test.cgi lin
+e 58.<br>
Line 58 is the next line after "&test;" where I call another subroutine (that works fine, and has absolutely nothing to do with sessions at all). If I edit out this line, the error simply skips to the next active line in the code... so it's obviously being generated by the &test subroutine.
Can anyone shed some light on what might be causing the code to not work properly in a subroutine, but work fine in the body of the code?
Regards,
Stenyj
20050408 Edit by ysth: use id:// instead of link with domain name
Edit by tye: put long error text in CODE tags
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.