Re: how to add a list of numbers

2006-07-21 Thread tom arnall
On Thursday 20 July 2006 12:27 pm, Charles K. Clarkson wrote: > tom arnall wrote: > : Whatever happened to good old: > : > : my (@data,$result); > > Why declare these ... > > : @number = (1,2,3); > : $sum = 0; > > And then use these? > > Go ahead. Hit yourself upside the hea

RE: how to add a list of numbers

2006-07-20 Thread Charles K. Clarkson
tom arnall wrote: : Whatever happened to good old: : : my (@data,$result); Why declare these ... : @number = (1,2,3); : $sum = 0; And then use these? Go ahead. Hit yourself upside the head. :) Yet another reason to declare variables only as they are first

RE: how to add a list of numbers

2006-07-20 Thread Timothy Johnson
-Original Message- From: tom arnall [mailto:[EMAIL PROTECTED] Sent: Thursday, July 20, 2006 12:08 PM To: beginners@perl.org Subject: Re: how to add a list of numbers > > > Whatever happened to good old: > > my (@data,$result); > @number = (1,2,3)

Re: how to add a list of numbers

2006-07-20 Thread tom arnall
On Friday 14 July 2006 11:00 pm, I BioKid wrote: > is there any shortest way to add a list of random numbers ? > for example : > 11 > 1 > 250 > 39 > 100 Whatever happened to good old: my (@data,$result); @number = (1,2,3); $sum = 0; foreach(@number) {

Re: how to add a list of numbers

2006-07-15 Thread WCJ d/b/a http://ccsh.us/
On 7/15/06, I BioKid <[EMAIL PROTECTED]> wrote: is there any shortest way to add a list of random numbers ? for example : 11 1 250 39 100 my $results; while(){ s|\s+||g; $results += $_; } print $results; __END__ 11 2 250 39 -- WC (Bill) Jones -- http://youve-reached-the.endoftheinterne

RE: how to add a list of numbers

2006-07-15 Thread Jeff Peng
Hello,how about this? use strict; my $maxLenth=16; my @a = (0..99); my @randList = map { $a[int rand @a] } 0..($maxLenth-1); print "@randList\n"; Here $maxLenth is the list's length,@a is the source where the list members coming from. is there any shortest way to add a list of random num

Re: how to add a list of numbers

2006-07-14 Thread Aaron Priven
Well, you can add a list of numbers with the module List::Util . It has a routine called "sum". my @list = (8,10,2,5); use List::Util qw(sum); my $sum = sum (@list); # $sum is now 25 It can add any numbers, random or not. On Jul 14, 2006, at 11:00 PM, I BioKid wrote: is there an

how to add a list of numbers

2006-07-14 Thread I BioKid
is there any shortest way to add a list of random numbers ? for example : 11 1 250 39 100 , thanks -- ibiokid