[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Parsing rfc822 headers



Roland Giersig wrote:

> Christian Borup wrote:
> > I just came up with this sub that parses a rfc822 header and stuffs it
> > into a array of hashes (yes - it works).
> >
> > sub headers {
> >   return [ map { my $q= {}; @{$q}{'key','value'}= split(/:\s+/, $_, 2);
> > $q } split(/\n(?!\s)/, $_[0]) ];
> > }
>
> I don't get it. Why return a list of hashes? Don't you want
> just a hash with the header names as keys and the (possible
> multiple) values as list refs?

Nope, I pass the result on to a template driven output thingie (a rather
nifty one I might ). Also I want them in the original order. But seperating
the headers into one hash like you say is much simpler, and can be done with
rather less code.

The sub as presented does what I want, but $q annoys my to no end. Surely, I
must be missing something.

- Borup


==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org