* Paul Lalli [2008.06.19 13:52]:
> On Jun 19, 11:41 am, [EMAIL PROTECTED] (Jean-Rene David) wrote:
> > I have an array of integers and two indexes within
> > that array. I need to get another array identical
> > to the first one, except that all cells between
> > the two indexes (inclusive) must be compressed to
> > one column which is the sum of the originals
> > cells.
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> use List::Util qw/sum/;
> 
> my @array = qw{ 10 20 30 40 50 };
> my $start = 1;
> my $end   = 3;
> 
> my @out = @array;
> splice @out, $start, ($end - ($start - 1)), sum(@array[$start..$end]);
> 
> local $\="\n";
> print for @out;
> __END__

Beautiful. Thanks.

Thanks to John as well for the same answer.

-- 
JR

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


Reply via email to