Re: perl built in function for mean

2006-09-11 Thread Dr.Ruud
Rob Dixon schreef:
 Adriano Ferreira:
 Jen Spinney:
 Dr.Ruud:

   my$mean;mean+=$_/@data [EMAIL PROTECTED];

 Don't you need another dollar sign?
 my$mean;$mean+=$_/@data [EMAIL PROTECTED];

 Where is Rob to tell Dr. Ruud if one must test the code for him after
 he posts? Of course, Dr. Ruud meant the latter. We commit such errors
 all the time, but we fix them even faster.

 It wasn't me, it was Jen. And I believe he was quite right to post a
 correction like this on a beginners' group. It is the character
 assassinations from people who should know better that don't belong
 here.

Hihi, I must have assassinated that $ character while eliminating some
whitespace.

-- 
Affijn, Ruud

Gewoon is een tijger.



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




Re: perl built in function for mean

2006-09-10 Thread Bryan Harris


 Bryan Harris wrote:
 
 chen li wrote:
 
 I want to calculate the mean of an array. I know how
 to let the job done by using a loop. But I just wonder
 if Perl has the short-cut/built-in function for this.
 
 my @data=(1,1,1);
 
 mean=(1+1+1)/3=1;(Any perl built-in function for
 this?)
 my $mean = do { my $s; $s += $_ for @data; $s / @data };
 
 I can't believe I just beat John in perl golf, by 14 strokes!
 
 (Anyone who knows me knows I just got lucky on that hole...)
 
 Well, if you want to golf that:
 
 my$mean=(map$a+=$_/@data,@data)[-1];


Looks like a tie now!  Neat.

I wonder (only a little) which way is more efficient...

- B



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




Re: perl built in function for mean

2006-09-10 Thread John W. Krahn
Bryan Harris wrote:
 
Bryan Harris wrote:
chen li wrote:

I want to calculate the mean of an array. I know how
to let the job done by using a loop. But I just wonder
if Perl has the short-cut/built-in function for this.

my @data=(1,1,1);

mean=(1+1+1)/3=1;(Any perl built-in function for
this?)
my $mean = do { my $s; $s += $_ for @data; $s / @data };
I can't believe I just beat John in perl golf, by 14 strokes!

(Anyone who knows me knows I just got lucky on that hole...)
Well, if you want to golf that:

my$mean=(map$a+=$_/@data,@data)[-1];
 
 
 Looks like a tie now!  Neat.
 
 I wonder (only a little) which way is more efficient...

perldoc Benchmark



John
-- 
use Perl;
program
fulfillment

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




Re: perl built in function for mean

2006-09-10 Thread Dr.Ruud
John W. Krahn schreef:

 my$mean=(map$a+=$_/@data,@data)[-1];

  my$mean;mean+=$_/@data [EMAIL PROTECTED];

-- 
Affijn, Ruud

Gewoon is een tijger.



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




Re: perl built in function for mean

2006-09-10 Thread Randal L. Schwartz
 chen == chen li [EMAIL PROTECTED] writes:

chen Since my script is pretty short I would prefer using
chen my own codes. I don't think I need to call this
chen module.

If you have hundreds of entries, you'll notice the difference.
The sum() that comes from List::Util is in C, not Perl.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: perl built in function for mean

2006-09-10 Thread Jen Spinney

On 9/10/06, Dr.Ruud [EMAIL PROTECTED] wrote:

  my$mean;mean+=$_/@data [EMAIL PROTECTED];


Don't you need another dollar sign?
my$mean;$mean+=$_/@data [EMAIL PROTECTED];

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




Re: perl built in function for mean

2006-09-10 Thread Adriano Ferreira

On 9/10/06, Jen Spinney [EMAIL PROTECTED] wrote:

On 9/10/06, Dr.Ruud [EMAIL PROTECTED] wrote:
   my$mean;mean+=$_/@data [EMAIL PROTECTED];

Don't you need another dollar sign?
my$mean;$mean+=$_/@data [EMAIL PROTECTED];


Where is Rob to tell Dr. Ruud if one must test the code for him after
he posts? Of course, Dr. Ruud meant the latter. We commit such errors
all the time, but we fix them even faster.

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




Re: perl built in function for mean

2006-09-10 Thread Rob Dixon

Adriano Ferreira wrote:

On 9/10/06, Jen Spinney [EMAIL PROTECTED] wrote:


On 9/10/06, Dr.Ruud [EMAIL PROTECTED] wrote:
   my$mean;mean+=$_/@data [EMAIL PROTECTED];

Don't you need another dollar sign?
my$mean;$mean+=$_/@data [EMAIL PROTECTED];


Where is Rob to tell Dr. Ruud if one must test the code for him after
he posts? Of course, Dr. Ruud meant the latter. We commit such errors
all the time, but we fix them even faster.


It wasn't me, it was Jen. And I believe he was quite right to post a correction
like this on a beginners' group. It is the character assassinations from people
who should know better that don't belong here.

Rob

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




Re: perl built in function for mean

2006-09-09 Thread Xavier Noria

On Sep 9, 2006, at 9:00 PM, chen li wrote:


I want to calculate the mean of an array. I know how
to let the job done by using a loop. But I just wonder
if Perl has the short-cut/built-in function for this.


There are modules, but nothing builtin.



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




Re: perl built in function for mean

2006-09-09 Thread Randal L. Schwartz
 Xavier == Xavier Noria [EMAIL PROTECTED] writes:

Xavier On Sep 9, 2006, at 9:00 PM, chen li wrote:
 I want to calculate the mean of an array. I know how
 to let the job done by using a loop. But I just wonder
 if Perl has the short-cut/built-in function for this.

Xavier There are modules, but nothing builtin.

List::Util is built-in as of 5.8, and back compatible to 5.5 I think.

use List::Util qw(sum);

my $average = sum(@input) / @input;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: perl built in function for mean

2006-09-09 Thread Xavier Noria

On Sep 9, 2006, at 9:48 PM, Randal L. Schwartz wrote:


Xavier == Xavier Noria [EMAIL PROTECTED] writes:


Xavier On Sep 9, 2006, at 9:00 PM, chen li wrote:

I want to calculate the mean of an array. I know how
to let the job done by using a loop. But I just wonder
if Perl has the short-cut/built-in function for this.


Xavier There are modules, but nothing builtin.

List::Util is built-in as of 5.8, and back compatible to 5.5 I  
think.


use List::Util qw(sum);

my $average = sum(@input) / @input;


I know, but that's not a builtin mean().



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




Re: perl built in function for mean

2006-09-09 Thread chen li
Thanks Xavier,

Since my script is pretty short I would prefer using
my own codes. I don't think I need to call this
module.

Li 

--- Xavier Noria [EMAIL PROTECTED] wrote:

 On Sep 9, 2006, at 9:48 PM, Randal L. Schwartz
 wrote:
 
  Xavier == Xavier Noria [EMAIL PROTECTED]
 writes:
 
  Xavier On Sep 9, 2006, at 9:00 PM, chen li wrote:
  I want to calculate the mean of an array. I know
 how
  to let the job done by using a loop. But I just
 wonder
  if Perl has the short-cut/built-in function for
 this.
 
  Xavier There are modules, but nothing builtin.
 
  List::Util is built-in as of 5.8, and back
 compatible to 5.5 I  
  think.
 
  use List::Util qw(sum);
 
  my $average = sum(@input) / @input;
 
 I know, but that's not a builtin mean().
 
 
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 http://learn.perl.org/
 http://learn.perl.org/first-response
 
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




Re: perl built in function for mean

2006-09-09 Thread Bryan Harris


$mean = eval(join(+, @data)) / @data;

I love perl golf.   =)

- B



 Dear all,
 
 I want to calculate the mean of an array. I know how
 to let the job done by using a loop. But I just wonder
 if Perl has the short-cut/built-in function for this.
 
 Thanks,
 
 Li 
 
 my @data=(1,1,1);
 
 mean=(1+1+1)/3=1;(Any perl built-in function for
 this?)
 
 
 
 __
 Do You Yahoo!?
 Tired of spam?  Yahoo! Mail has the best spam protection around
 http://mail.yahoo.com 



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




Re: perl built in function for mean

2006-09-09 Thread John W. Krahn
chen li wrote:
 Dear all,

Hello,

 I want to calculate the mean of an array. I know how
 to let the job done by using a loop. But I just wonder
 if Perl has the short-cut/built-in function for this.
 
 my @data=(1,1,1);
 
 mean=(1+1+1)/3=1;(Any perl built-in function for
 this?)

my $mean = do { my $s; $s += $_ for @data; $s / @data };


John
-- 
use Perl;
program
fulfillment

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




Re: perl built in function for mean

2006-09-09 Thread Bryan Harris


I can't believe I just beat John in perl golf, by 14 strokes!

(Anyone who knows me knows I just got lucky on that hole...)

- B



 chen li wrote:
 Dear all,
 
 Hello,
 
 I want to calculate the mean of an array. I know how
 to let the job done by using a loop. But I just wonder
 if Perl has the short-cut/built-in function for this.
 
 my @data=(1,1,1);
 
 mean=(1+1+1)/3=1;(Any perl built-in function for
 this?)
 
 my $mean = do { my $s; $s += $_ for @data; $s / @data };
 
 
 John



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




Re: perl built in function for mean

2006-09-09 Thread John W. Krahn
Bryan Harris wrote:
 
chen li wrote:

I want to calculate the mean of an array. I know how
to let the job done by using a loop. But I just wonder
if Perl has the short-cut/built-in function for this.

my @data=(1,1,1);

mean=(1+1+1)/3=1;(Any perl built-in function for
this?)
my $mean = do { my $s; $s += $_ for @data; $s / @data };

 I can't believe I just beat John in perl golf, by 14 strokes!

 (Anyone who knows me knows I just got lucky on that hole...)

Well, if you want to golf that:

my$mean=(map$a+=$_/@data,@data)[-1];



John
-- 
use Perl;
program
fulfillment

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