Thread Cookie-Hash ist leer (CGI)
(9 answers)
Opened by GwenDragon at 2010-10-27 14:14
Meine Änderung am Modul cookies macht genau das, was ich wollte. Mach jedenfalls das, was vom Erfinder vorgesehen war.
Geht wohl noch eleganter. Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 use strict; use warnings; package cookies; use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Useqq = 1; use CGI qw/:standard/; use CGI::Cookie; my %cookies = (); sub start { foreach ( cookie() ) { my %h = cookie($_); unless (exists $h{$_} ) { my (@h) = %h; @h = reverse @h; %h = ($_,$h[1]); } print '### Debug ### Cookie %h: ', Dumper(\%h), '###### '; $cookies{$_} = \%h; } 1; } sub get { my($name) = @_; return $name ? $cookies{$name} : \%cookies; } 1; package main; use CGI qw/:standard/; use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Useqq = 1; sub say { print "@_", "\n"; } my $cook1 = 'url=url&%2Fcms%2Fadmin%2Fx.cgi&test&77'; say $ENV{HTTP_COOKIE} = $cook1; cookies::start; say Dumper %cookies; my $c = cookies::get('url'); say $c->{'url'}; say $c->{'test'}; say; say '============='; $cook1 = 'url=%2Fcms%2Fadmin%2Fx.cgi'; say $ENV{HTTP_COOKIE} = $cook1; cookies::start; say Dumper %cookies; my $c = cookies::get('url'); say $c->{'url'}; say $c->{'test'}; say; 1; Danke für deine Bemühungen und Anregungen, kristian. |