> ########################## READ-COOKIE.CGI ###########################
> 
> #!/usr/bin/perl
> use CGI;
> use CGI::Cookie;
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
> use warnings;
> 
> my %cookies =3D fetch CGI::Cookie;
> my $cookies;
> my $id =3D $cookies{'ID'}->value;
> 
> IF the cookie already exists the script reads the value perfectly, but =
> if cookie doesn't exist or I mean for the first time visitor, it gives =
> error: "Can't call method "value" on an undefined value"
> 
> I tried to do something like it: if ($id) {do blah} else {do blah} but =
> that's not working either.
> 
> It's my first time using CGI::Cookie, how can I overcome this problem
> 
> Thanks for any input,
> 
> Sara.
> 
> 


check to see that the cookie exists before extracting its value

my $id = 'no cookie presented';
if ( exists $cookies{ID} ) {
    $id = $cookies{ID}->value;
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to