couchmonkey
11-02-2004, 10:24 AM
I'm working on a bit of an emergency project here, and I'm very much a Perl novice, so I apologize if this is obvious:
I'm retrieving a variable from a cookie, and then trying to check if it's value is equal to the string "yes". But I found through testing that in fact the string that I'm getting from the cookie is "greater than" yes concatonated with ascii 032 and "less than" yes concatonated with ascii 033.
I'm wondering if there's something obvious that I just don't know about Perl here, like some special trailing character that is saved in strings. Or maybe this is an artifact from the way we're saving the cookies (the cookie is encrypted with CGI::Blowfish).
Here's a snippet:
# SET COOKIE SNIPPET
$seen_message = "yes";
#There are more variables than $seen_message, i'm just simplifying
#to make it more readable
$info{SeenMsg} = $seen_message;
my $cookie = cookie::encrypt(\%info, $cookiename);
print $query->header(
-refresh=>"1; URL=$seturl",
-cookie=>$cookie
);
print "\n\n";
print $query->start_html;
print $query->end_html;
exit;
}
# RETRIEVE COOKIE SNIPPET
my %cookies = fetch CGI::Cookie;
if ($query->cookie($cookiename)) {
$infox = cookie::decode($query->cookie($cookiename));
$seen_message = $infox->{SeenMsg};
my $char;
my $char2;
$char = chr(32);
$char2 = chr(33);
# This following if statement is true when I previously set
# SeenMsg in the cookie to "yes"
if(($seen_message gt ("yes" . $char)) &&
($seen_message lt ("yes" . $char2)))
{
$seen_message = "The message is yes";
}
else {
$seen_message = "Actually it's " . $seen_message;
}
Edit: Added snippet from setting the cookie.
I'm retrieving a variable from a cookie, and then trying to check if it's value is equal to the string "yes". But I found through testing that in fact the string that I'm getting from the cookie is "greater than" yes concatonated with ascii 032 and "less than" yes concatonated with ascii 033.
I'm wondering if there's something obvious that I just don't know about Perl here, like some special trailing character that is saved in strings. Or maybe this is an artifact from the way we're saving the cookies (the cookie is encrypted with CGI::Blowfish).
Here's a snippet:
# SET COOKIE SNIPPET
$seen_message = "yes";
#There are more variables than $seen_message, i'm just simplifying
#to make it more readable
$info{SeenMsg} = $seen_message;
my $cookie = cookie::encrypt(\%info, $cookiename);
print $query->header(
-refresh=>"1; URL=$seturl",
-cookie=>$cookie
);
print "\n\n";
print $query->start_html;
print $query->end_html;
exit;
}
# RETRIEVE COOKIE SNIPPET
my %cookies = fetch CGI::Cookie;
if ($query->cookie($cookiename)) {
$infox = cookie::decode($query->cookie($cookiename));
$seen_message = $infox->{SeenMsg};
my $char;
my $char2;
$char = chr(32);
$char2 = chr(33);
# This following if statement is true when I previously set
# SeenMsg in the cookie to "yes"
if(($seen_message gt ("yes" . $char)) &&
($seen_message lt ("yes" . $char2)))
{
$seen_message = "The message is yes";
}
else {
$seen_message = "Actually it's " . $seen_message;
}
Edit: Added snippet from setting the cookie.