Blair Zajac <[EMAIL PROTECTED]> writes:

> I'm working on some code where it would be handy to know the number of
> removed HTTP headers with the HTTP::Headers->remove_header method.  Here's
> a small patch returns the number of deleted headers.

Would it make more sense to have it return the removed headers like
Perl's delete does for hashes?

Or we could have it return the count in scalar context and the removed
headers in list context.  Hmmm...

> Even if you choose not to apply it, there's a spelling fix patch in here
> in the last section.
> 
> Best,
> Blair
> 
> -- 
> Blair Zajac <[EMAIL PROTECTED]> - Perl & sysadmin services for hire
> Web and OS performance plots - http://www.orcaware.com/orca/--- Headers.pm.orig      
> Fri Apr 13 00:25:55 2001
> +++ Headers.pm        Mon Nov 12 21:05:35 2001
> @@ -171,18 +171,24 @@
>  
>  =item $h->remove_header($field,...)
>  
> -This function removes the headers with the specified names.
> +This function removes the headers with the specified names.  It
> +returns the number of headers removed.
>  
>  =cut
>  
>  sub remove_header
>  {
>      my($self, @fields) = @_;
> +    my $removed = 0;
>      my $field;
>      foreach $field (@fields) {
>       $field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
> -     delete $self->{lc $field};
> +     $field = lc($field);
> +     next unless exists $self->{$field};
> +     delete $self->{$field};
> +     ++$removed;

If the deleted thing is a header that repeats you probably want to
count that too.  Something like this might do:

  my $f = delete $self->{$field};
  $removed += ref($f) ? @$_ : 1;

>      }
> +    $removed;
>  }
>  
>  
> @@ -196,7 +202,7 @@
>  
>      my $lc_field = lc $field;
>      unless(defined $standard_case{$lc_field}) {
> -     # generate a %stadard_case entry for this field
> +     # generate a %standard_case entry for this field
>       $field =~ s/\b(\w)/\u$1/g;
>       $standard_case{$lc_field} = $field;
>      }

Reply via email to