i can't figure out why save_param from a session object can't seem to save keys that existed before with a undef value.
a simple test shows here : (u can see that my name is gone only after assigning an empty string when saving)
#test1.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Session qw/-ip-match/;
# instantiate a new CGI object
my $cgi = new CGI;
my $session = new CGI::Session();
my $sessionid = $session->id();
$cgi->param("myname", "max payne");
#save param into session
$session->save_param($cgi);
print "after saving, it's actually : ";
print $session->param("myname");
print $cgi->redirect( -URL => 'test2.pl?sessionid='.$sessionid);
#test2.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Session qw/-ip-match/;
require "library.pl";
# instantiate a new CGI object
my $cgi = new CGI;
my $sessionid = $cgi->param("sessionid");
# MARKING 1
my $session = CGI::Session->load($sessionid);
print "what was my name again >? " . $session->param("myname");
$cgi->param("myname", undef);
$session->save_param($cgi);
print "<BR>(as undef) what was my name again >? " . $session->para
+m("myname");
$cgi->param("myname", "");
$session->save_param($cgi);
print "<BR>(as empty string) what was my name again >? " . $sessio
+n->param("myname");
it actually outputs :
what was my name again >? max payne
(as undef) what was my name again >? max payne
(as empty string) what was my name again >?
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.