in reply to Re: Weird Regex in CGI::Cookie
in thread Weird Regex in CGI::Cookie
I second that, whole-heartedly. In fact, here's my suggestion for a better version (hoping I understand the intent correctly):
I've only tested it to the extent that the assignments to %results match the original code (except for the trailing whitespace glitch) -- that is, a "raw_cookie" string like this:sub raw_fetch { my $class = shift; my $raw_cookie = get_raw_cookie(@_) or return; my %results; $raw_cookie =~ s/^\s+//; $raw_cookie =~ s/\s+$//; my(@pairs) = split(/\s*;\s*/,$raw_cookie); foreach (@pairs) { my ($key,$val) = (/^([^=]+)=?(.*)/); $results{$key} = $val; } return \%results unless wantarray; return %results; }
one=1 ;two=2; three=the third ; four= ; five ; six = the sixth ;produces these key/value pairs:
'one'=>'1', 'two'=>'2', 'three'=>'the third', 'four'=>'', 'five'=>'', 'six '=>' the sixth'(note that spaces next to "=" are not deleted)
|
|---|