"Matej Kovacic" <[EMAIL PROTECTED]> writes:

> Suppose I send a http request... and get all HTTP headers.
> Then I use $r->headers_as_string.
> 
> But some servers has "doubled" header variables - for instance, I get this:
>    Content-Type: text/html; charset=iso-8859-2
>    Content-Type: text/html; charset=ISO-8859-2

The main source of doubled content-type headers is that LWP normally
invoke the HTML::HeadParser and will then also pick up the header from
<meta http-equiv="Content-type" ....>.

> If I print this out using $r->header("Content-Type"), I get this:
> text/html; charset=iso-8859-2text/html; charset=ISO-8859-2
> 
> The problem: how to separate two same header variables into an array for
> instance?

When you call $r->header() in scalar context it will give you all the
headers with the given name as a single string.  The headers will be
separated by ", ".  Try:

  print scalar($r->header("Content-Type"));

When you call $r->header() in list context if will return each header
as a separate element.  For instance:

  @ct = $r->header("Content-Type");

will in your example give a 2 element @ct.

Print evaluate its arguments in array context and outputs them without
any separator (unless you set $,).  That's the reason for the output
you saw.

Regards,
Gisle

Reply via email to