Loading ...
Sorry, an error occurred while loading the content.

[PBML] Re: Cookies

Expand Messages
  • Greg
    Excellent! ... I came
    Message 1 of 2 , Apr 30, 2003
    • 0 Attachment
      Excellent!
      ---------------------------------------------------------------
      --- In perl-beginner@yahoogroups.com, Hudson T Clark
      <dark_archon1@j...> wrote:
      > I was working on other code for all this CGI I have been doing but
      I came
      > up rather quickly with these two routines to do what you are talking
      > about, just thought I would share:
      >
      > sub EncodeString {
      > my %cookdata = @_;
      > my ($key, $value) = each %cookdata;
      > my $data = $key . '=' . $value;
      > while(($key, $value) = each %cookdata) {
      > $data = $data . '|' . $key . '-' . $value;
      > }
      > return $data;
      > }
      >
      > sub DecodeString {
      > my $data = $_[0];
      > my @tmp = split /\|/, $data;
      > my %cookdata;
      > foreach (@tmp) {
      > my ($key, $value);
      > ($key, $value) = split /=/, $_ if $_ eq $tmp[0];
      > ($key, $value) = split /-/, $_ unless $_ eq $tmp[0];
      > $cookdata{$key} = $value;
      > }
      > return %cookdata;
      > }
      >
      > [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.