Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
Please look at the code below.For the first time when script is called it is displayed correctly but for any other pages after this prints the whole cookie information on top of the screen.And it works correctly with last parameter blank,but does not work if some value is passed.Please tell me where lies the problem.
Thanks
blazix
sub getCookieValues { require "cgi-lib.pl"; $called_by_admin = shift; $remVal = shift; $eventChoice = shift; $path = "../home/home.pl"; local($IDENTITY); my @UserInfo; my $sProjName; my $eventVal; if($IDENTITY = &parseCookie()){ #print &PrintHeader; @UserInfo = split(/\|/, $IDENTITY); if(($remVal ne "")||($eventChoice ne "")) { if($remVal ne "") { $eventVal = pop @UserInfo; $tempVal = pop @UserInfo; if($tempVal ne $remVal) { push @UserInfo,$remVal; push @UserInfo,$eventVal; $IDENTITY = join("|", @UserInfo); print "set-cookie: WBSession=$IDENTITY; p +ath=/cgi-bin;\n\n"; } else { push @UserInfo,$tempVal; push @UserInfo,$eventVal; $IDENTITY = join("|", @UserInfo); print "set-cookie: WBSession=$IDENTITY; p +ath=/cgi-bin;\n\n"; } } if($eventChoice ne "") { $eventVal = pop @UserInfo; if($eventVal ne $eventChoice) { push @UserInfo,$eventChoice; $IDENTITY = join("|", @UserInfo); print "set-cookie: WBSession=$IDENTIT +Y; path=/cgi-bin;\n\n"; } else { push @UserInfo,$eventVal; $IDENTITY = join("|", @UserIn +fo); print "set-cookie: WBSession= +$IDENTITY; path=/cgi-bin;\n\n"; } } } else { print &PrintHeader; } } else { $username = $in{'Username'}; $password = $in{'Password'}; $sProjName = $in{'Project'}; if($username && $password){ $IDENTITY = &setCookie($username, $password, $path, $sProj +Name,"rem","ALL EVENTS"); @UserInfo = split(/\|/, $IDENTITY); } else{ &login($path); } } $username = $UserInfo[1]; unless ($called_by_admin){ verifyUser($username); } return @UserInfo; } # end getCookieValues sub routine

Replies are listed 'Best First'.
Re: where is the error ??
by TrekNoid (Pilgrim) on Jul 22, 2004 at 19:03 UTC
    First thing I saw was this:

    if($IDENTITY = &parseCookie())
    I believe that's going to *always* be true, since = is the assignment operator

    Trek

      No, only if parseCookie() always returns a true value. Sometimes an = is really what you mean in a boolean context.

        Sometimes an = is really what you mean in a boolean context.

        And *that* is why I'm only level 4... Maybe level 3 by the time this node gets downvoted :)

        Oh well... sometimes lessons are learned the hard way...

        Trek

        Thanks Monks for your immediate replies.But I got the solution ie., if I pass remval,eventchoice values the cookie is set twice and gets printed but now I changed the code to set cookie after doing all the changes. I appreciate all for your immediate guidance Blazix