in reply to hashes filling up with funk

Sorry, yes here is some code.. its a CGI . At first I didn't think it was the code because the code is old and this just started to happen recently. Thanks!
sub CookieCutter { my $raw_dough = "@_"; my ($cookie, $key, $value); undef %Cookies; foreach $cookie (split / /, $raw_dough) { if (not ($key, $value) = ($cookie =~ /^([^\=]+)\=([^\;\s]+)/)) + { if (($key) = ($cookie =~ /^([^\=]+)\=[\;\s+]/)) { $value = ''; } } $Cookies{ $key } = $value; } }

Replies are listed 'Best First'.
Re: Re: hashes filling up with funk
by Chady (Priest) on May 01, 2001 at 22:20 UTC

    what's that?? manually??

    look at CGI.pm, it will handle all the fuss for you..

    not mentioning that the code in itself is a bit ugly and pointless

    Update: so it's probably due to the cookie value being escaped, and since you're not using CGI.pm, are you doing this?

    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    on the cookie value to un-escape it??


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
      Heh yea, I know... CGI.pm would replace that code nicely. But I don't have that luxury unfortunately... I am dealing with legacy code at work and even more legacy coders and their petty politics. Hopefully that routine has an error in it so I can pass the buck. ;)
        symŽ wrote:
        CGI.pm would replace that code nicely. But I don't have that luxury unfortunately
        Not true. You mentioned that you have Perl 5.00503. That includes CGI.pm as one of the standard modules. If your fellow programmers cannot appreciate good, solid code that functions better than what currently exists, why are they programmers?

        Side note: Is it just me, or has anyone else noticed that I'm getting a bit "rougher" in my posts?

        Cheers,
        Ovid

        Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

(Ovid - cookies) Re(2): hashes filling up with funk
by Ovid (Cardinal) on May 01, 2001 at 22:36 UTC
    If you use CGI.pm, here's how to get your cookies (straight from the POD!):
    %cookies = fetch CGI::Cookie;

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Re: hashes filling up with funk
by Anonymous Monk on May 02, 2001 at 00:54 UTC
    Are you sure this piece of code is the problem, and not the code that sets the cookie? Can you log $cookie to make sure it's good before chewing on it?
      totally, thats a good point. I'll do that. Although the code is still suspect! :) I guess that what I was really trying to ask about is, Could %00 'null' could be populated on a lower level for some reason
        Sure, it could be passed along in whatever it is that gets sent to your CookieCutter sub. Personally I would print out whatever is going in to see if it is clean - I'd wager if you have such a problem with politics and legacy code, you can have problems anywhere.

        Also, neat trick while playing with cookies.

        javascript:alert(document.cookies);

        in your browsers location bar will throw up an alert box with all your cookies for that site and their values.

        EEjack