perlguru22 has asked for the wisdom of the Perl Monks concerning the following question:
How can you find the sum of an array using just shift and pop?
I tried using a for loop but I don't think that worked either.#! usr/bin/perl @nums = (1,2,3,4); $s = shift@nums; \\ I know that gives $s 1 $p = pop@nums; \\ This gives $p 4 $sum += $_ for @nums; print "$sum";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: using pop and shift to find the sum of an array
by Athanasius (Archbishop) on Sep 22, 2012 at 07:39 UTC | |
Re: using pop and shift to find the sum of an array
by 2teez (Vicar) on Sep 22, 2012 at 06:14 UTC | |
Re: using pop and shift to find the sum of an array
by johngg (Canon) on Sep 22, 2012 at 12:25 UTC | |
Re: using pop and shift to find the sum of an array
by tobyink (Canon) on Sep 22, 2012 at 10:52 UTC |
Back to
Seekers of Perl Wisdom