R. Joseph Newton wrote:

I'll do some more scanning through my hdr directory to see how many folded lines
I actually see. Ooooh!  I see The To line can also get folded.  I think the
trick that I showed for testing for initial space should work for that  It is
very clear that the input processing has to use some sort of $curent_tag and
$current_value scoped outside the input loop to handle this., Headers like
Received should indeed be pulled aside for special handling, but I do not think
you will find that many in actual use.

One obvious, but questionable way to deal with fields that may appear multiple times would be something like (the untested code below):


# assume we have a complete header field in $field
# and $header is a hash containing all fields in the current header

my ($k,$v) = split( /:\s*/, $field, 2 );
if (exists $header{$k} && ref($header{$k} eq 'ARRAY') {
  # we've already encountered this field more than once
  # so we just push it onto the already existing array
  push @{ $header{$k} }, $v;
} elsif (exists $header{$k}) {
  # this is the second time encountering this field
  # so we convert from a simple scalar to an array.
  my $old_v = $header{$k};
  push @{ $header{$k} }, $old_v, $v;
} else {
  # this is our first encounter with this field
  # assume it is a simple scalar
  $header{$k} = $v;
}

The obvious disadvantage is that every time the user accesses a field, she must test to see if it is an array or simple scalar. There are ways to overcome by converting to an object and providing accessors and such, but thankfully, there already exists modules to do this for you.

Randy.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to