Gossamer Forum
Home : General : Perl Programming :

GT::CGI and reading cookies

Quote Reply
GT::CGI and reading cookies
I use the GT::CGI in preference to the CGI.pm and have found when I upgraded the GT::CGI from the 1.45 version to 1.93 it broke some code for reading cookies.

I need to know how to deference cookies, its not as the doco says or am

I missing something?

from doco: "or to retrieve a hash of all cookies:

my $cookies = $cgi->cookie; "and the print $cookies->{'thecookie'} ;Basically the code is:

#!/usr/bin/perl -w
use strict ; # This is what flushes out the error

sub main()
use GT::CGI;

my $IN = new GT::CGI;

my $cookies = $IN->cookie ; # all cookies in a hash now

print $IN->header() ; # all output to browser now

print "User = $cookies->{UserID}" ;


I get the dreaded

"Can't use string ("5") as a HASH ref while "strict refs" in use" which I believe to do with a has ref being treated as a scalar instead of as a variable.

Can someone let me know how I am supposed to dereference the cookie values?

Thanks Smile doug


Below are the relevent bits from the GT::CGI module's

# ==================================================================
# Gossamer Threads Module Library - http://gossamer-threads.com/
# Author : Aki Mimoto
# CVS Info : 087,070,085,093,083
# $Id: CGI.pm,v 1.45 2001/02/06 01:40:32 alex Exp $

Code above works fine.

sub cookie {

if (@_ == 0) {
return wantarray ? keys %COOKIES : \%COOKIES;
} etc etc


New module causes problem as described.

# Author : Aki Mimoto
# CVS Info : 087,071,081,089,087
# $Id: CGI.pm,v 1.93 2001/11/28 03:16:54 jagerman Exp $

sub cookie {

if (@_ == 0) { # Return keys.
return keys %{$self->{cookies}};
} etc etc


Quote Reply
Re: [dougrobb] GT::CGI and reading cookies In reply to

Thanks, we'll update the docs! The cookie() method behaves just like param() now. If called with no arguments it returns a list of valid cookies. So you would do:

foreach my $cookie ($IN->cookie) {
print "cookie $cookie has a value of ", $IN->cookie($cookie), "\n";


Gossamer Threads Inc.
Quote Reply
Re: [Alex] GT::CGI and reading cookies In reply to
Thanks Alex, they are a great set of modules.

regards doug