On Sun, Jan 28, 2001 at 11:17:51AM +0000, Simon Cozens wrote:
> On Sun, Jan 28, 2001 at 01:06:31AM +0100, [EMAIL PROTECTED] wrote:
> > I don't think there are any good examples. If there were any good
> > examples, it would mean chop would be a useful function to have.
> > But after the arrival of chomp, they only reason to keep chop is backwards
> > compatability.
> 
> chomp gets rid of what my system calls newlines. chop gets rid of newlines
> in data that comes from other systems too.
> 
> The following fragment is from some production code; we're turning a bunch of
> relative (percentage) and absolute sizes into all absolutes.
> 
>   my @percents = grep /\d+%$/, @sizes;
>   croak "At least one argument to ->sizes() needs to be pixels"
>     unless @percents < @sizes;
>   my @constants = grep { !/\d+%/ } @sizes;
>   # Right.
>   my $c = 0; $c += $_ for @constants;
>   chop @percents;
>   my $p = 0; $p += $_ for @percents;
> 
> The chop is there to get rid of "argument not numeric" warnings.

If you write the first grep as a map, there's no need for chop:

    my @percents = map {/(\d+)%$/} @sizes;



Abigail

Reply via email to