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
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
-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)
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) {
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
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
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
is there any shortest way to add a list of random numbers ?
for example :
11
1
250
39
100
,
thanks
--
ibiokid