Okay, the CGI module works great. Now I need to set/read another cookie in the same script, so I made a copy of the original %cookies hash, so it looked like:
Code:
my %sources = (
name => 'sections',
expires => '+3y',
path => '/',
domain => 'ucmd.virtualave.net'
);
And in the subroutine where the cookie would be read, I added:
Code:
my $content = $in->cookie($sources{'name'});
So the entire sub looks like the following:
Code:
sub headlines {
my $in = shift;
my $content = $in->cookie($sources{'name'});
$us = &us_lines;
$w = &w_lines;
$b = &b_lines;
$t = &t_lines;
$h = &h_lines;
$s = &s_lines;
$cm = &cm_lines;
$ob = &ob_lines;
if ($content ne '') { #check for a cookie
@section = split(/x/, $content); #split the cookie up so we can read it
foreach $section (@section) { #don't display unwanted sections
$headlines .= qq|$us| unless ($section eq 'us');
$headlines .= qq|$w| unless ($section eq 'w');
$headlines .= qq|$b| unless ($section eq 'b');
$headlines .= qq|$t| unless ($section eq 't');
$headlines .= qq|$h| unless ($section eq 'h');
$headlines .= qq|$s| unless ($section eq 's');
$headlines .= qq|$cm| unless ($section eq 'cm');
$headlines .= qq|$ob| unless ($section eq 'ob');
}
}
else {
#display everything
$headlines .= "$us$w$b$t$h$s$cm$ob";
}
return ($headlines);
}
When I run the script, I get the following error:
Code:
Can't call method "cookie" on an undefined value at C:\HTTPD\CGI-BIN\music\portal.cgi line 225.
Which is the the "my $content" line above. If I comment the line out, the script proceeds as I expected it to when null or no cookie is found. What am I missing here? Unfortunately I only have LWP on my localhost but not on my server so I can't show you what it should look like when it's working.
--Drew