> ------=_NextPart_000_0000_01C4D891.DE901AA0 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: 7bit > > Hello again, > I have a problem with cookies; I can retreive cookies i have set, but if I > try to retreive a cookie that hasnt yet been set i get the following error: > > Can't call method "value" on an undefined value at viewcart.pl line 55. > > I am trying to get my cookie using: $ID = $newcook{'usrID'}->value; which > works fine unless this cookie hasnt been set. This is all part of a shopping > cart and that the reason why the possibility arises that someone may veiw > their empty cart and therefore no cookie will have been created. > > Anyway, my question is: how do I test to see if a coockie exists b 4 i try > to read it ??? >
# TMTOWTDI - but they will all revolve around using ref() to determine that $newcook{usrID} is # some kind of object (if you were paranoid or anal retentive, you would check ref against the object class # you expect to see...) $ID = ref($newcook{usrID}) && $newcook{usrID}->value; # $ID will be an empty string if there is no cookie $ID = $newcook{usrID}->value if ref($newcook{usrID}); # if there is no cookie, $ID will be untouched (maybe undef?) $ID = ( ref($newcook{usrID} ? $newcook{usrID}->value : 'no cookie set yet' ); # $ID will get *SOME* value you can change to suit your system. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 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>