You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by ted <mp...@netcasters.com> on 2005/04/21 21:14:15 UTC
Reading err_headers_out values
Hi,
I am baking three cookies, then attempting to see them using the
err_headers_out method. The problem is that when baked, the key
for each cookie is the same: 'Set-Cookie'. The Apache::Table
object is ok with this, but when it is tied to the perl hash
the duplicate keys seem to trip things up. I cannot see the
individual values. Is there any way to retrieve the values?
Thanks,
Ted
my $cookie1 = Apache::Cookie->new($r,
-name => 'oranges',
-value => 1,
-path => "/", );
$cookie1->bake();
my $cookie2 = Apache::Cookie->new($r,
-name => 'apples',
-value => 1,
-path => "/", );
$cookie2->bake();
my $cookie3 = Apache::Cookie->new($r,
-name => 'lemons',
-value => 1,
-path => "/", );
$cookie3->bake();
my $h = $r->err_headers_out();
warn "1st while ...\n";
while (my($k, $v) = each %$h) { warn "k = $k v = $v\n"; }
my %h = $r->err_headers_out();
warn "2nd while ...\n";
while (my($k, $v) = each %h) { warn "k = $k v = $v\n"; }
-------------------------------
Output:
1st while ...
k = Set-Cookie v = oranges=1; path=/
k = Set-Cookie v = oranges=1; path=/
k = Set-Cookie v = oranges=1; path=/
2nd while ...
k = Set-Cookie v = lemons=1; path=/
Re: Reading err_headers_out values
Posted by Jonathan Vanasco <jv...@mastersofbranding.com>.
At first look, it makes sense -- '1st while' is dealing with the scalar
reference, '2nd while' is reading it into a hash
but then i notice that there are 3 oranges, and 1 lemon
now i feel a few pieces short of a fruit salad.
(drum roll, please)
sorry, i didn't have my morning espressos today.
this makes no sense to me, as neither seem to be working
whenever i end up in something like this, i make extensive use of
Data::Dumper, and trace the hell out of my data structures to figure
out how their internal structure
also, as a note, i created my own cookie class -- well actually not a
class, but a couple of functions that probably should have been a
class. it lets me define how i want to handle cookies, then dispatches
the incoming cookie data to the right class and functions. i did it to
easily switch between the bake and headers out stuff. its not all too
messy, and i can switch stuff in one place to redefine all my cookies
(as all my cookie functions exist as building a data hash and
dispatching it to this central cookie cutter.
On Apr 21, 2005, at 3:14 PM, ted wrote:
> my $h = $r->err_headers_out();
> warn "1st while ...\n";
> while (my($k, $v) = each %$h) { warn "k = $k v = $v\n"; }
>
> my %h = $r->err_headers_out();
> warn "2nd while ...\n";
> while (my($k, $v) = each %h) { warn "k = $k v = $v\n"; }
>
> -------------------------------
> Output:
>
> 1st while ...
> k = Set-Cookie v = oranges=1; path=/
> k = Set-Cookie v = oranges=1; path=/
> k = Set-Cookie v = oranges=1; path=/
> 2nd while ...
> k = Set-Cookie v = lemons=1; path=/
>
Re: Reading err_headers_out values
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
ted wrote:
> Hi,
>
> I am baking three cookies, then attempting to see them using the
> err_headers_out method. The problem is that when baked, the key
> for each cookie is the same: 'Set-Cookie'. The Apache::Table
> object is ok with this, but when it is tied to the perl hash
> the duplicate keys seem to trip things up.
well, it's the nature of a hash. no surprises there :)
> I cannot see the
> individual values. Is there any way to retrieve the values?
if you want to iterate the headers use
$r->err_headers_out->do(sub {...}); # see the docs for sub syntax
if you want to retrieve a list of values try
$r->err_headers_out->get('Set-Cookie');
HTH
--Geoff