Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does one find the total (sum) of an array? 8

Status
Not open for further replies.

rdyoll

Technical User
Aug 11, 2003
39
0
0
US
Hi, let's say I have:

@numbers = qw/34 56 78 83 23 99 10/;

How can I find the "sum" of all the elements in the array?

I've tried pushing a "+" (plus sign) into the array and adding it up that way, but there has to be a better way.

The total is 383, but, I don't know the routine to follow to calculate this properly. Anyone?
 
The beauty of Coderifous script is that it truly demonstrates TMTOWTDI. I wouldn't have thought of

[red]$total = eval join '+', @numbers;[/red]

... in a million years!


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top