http://www.perlmonks.org?node_id=838491


in reply to Get the order of HTTP request headers

> # %ENV is in random order

You do realize that hashes do not keep their order, right? They are designed for random access. If you want data back in the original order, use an array.

my @header = map { [lc($_) , $q->http($_)] } $q->http; print "$_[0] => $_[1]\n" for @header";

Replies are listed 'Best First'.
Re^2: Get the order of HTTP request headers
by Anonymous Monk on May 05, 2010 at 11:29 UTC
    Ahem, %ENV is %ENV
    'http' => <<'END_OF_FUNC', sub http { my ($self,$parameter) = self_or_CGI(@_); if ( defined($parameter) ) { $parameter =~ tr/-a-z/_A-Z/; if ( $parameter =~ /^HTTP(?:_|$)/ ) { return $ENV{$parameter}; } return $ENV{"HTTP_$parameter"}; } return grep { /^HTTP(?:_|$)/ } keys %ENV; } END_OF_FUNC
Re^2: Get the order of HTTP request headers
by arc_of_descent (Hermit) on May 05, 2010 at 11:32 UTC

    Yes. My point was that although $q->http returns a list of HTTP header names, they are not in the same order as the request headers were sent.