Re: Summary for mean/average calculation in perl

2006-09-10 Thread Bryan Harris
> :: ... and cute tricks should only be used in cute programs. > : > : I'll take that as a compliment -- thanks, John! > > He said cute programs, not cute programmers. ... that he thought it was a cute trick, not me. Ha ha. - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additi

RE: Summary for mean/average calculation in perl

2006-09-10 Thread Charles K. Clarkson
Bryan Harris wrote: :: ... and cute tricks should only be used in cute programs. : : I'll take that as a compliment -- thanks, John! He said cute programs, not cute programmers. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't t

Re: Summary for mean/average calculation in perl

2006-09-10 Thread Bryan Harris
> chen li wrote: >> >> --- "John W. Krahn" <[EMAIL PROTECTED]> wrote: >> >>> chen li wrote: >>> 6)$mean = eval(join("+", @data)) / @data; Depending on how you understand Perl and what >>> progress you are I prefer 6). >>> Depending on how you understand Perl, 6 is the wors

Re: Summary for mean/average calculation in perl

2006-09-10 Thread John W. Krahn
chen li wrote: >>>4)my $mean = do { my $s; $s += $_ for @data; $s / >>>@data }; > > I never see the usage of "for" like this before. Is it > equal to the following? Yes, except that above $s is only visible inside the code block while below $s is visible to the file. > And where can I find some

Re: How to chek the nth column of a delimited file

2006-09-10 Thread Rob Dixon
[EMAIL PROTECTED] wrote: Hi all, I have to re-process a delimited file but I only need to proceed records from the file that satisfy a specific condition. Can someone advise what is the best way to do this? For example, if I have this file here A~BB~CCC~DDD~~D~ A~BB~CCC~DDD~~D

Re: Summary for mean/average calculation in perl

2006-09-10 Thread chen li
> > 4)my $mean = do { my $s; $s += $_ for @data; $s / > > @data }; Hi, I never see the usage of "for" like this before. Is it equal to the following? And where can I find some more like this? my $s; for(@data){$s += $_ ;} my $mean=$s/@data; Thanks, Li

Re: How to chek the nth column of a delimited file

2006-09-10 Thread John W. Krahn
[EMAIL PROTECTED] wrote: > Hi all, Hello, > I have to re-process a delimited file but I only need to proceed records from > the file that satisfy a specific condition. Can someone advise what is the > best > way to do this? For example, if I have this file here > > > A~BB~CCC~DDD~~D~1

Re: Re unexpected result

2006-09-10 Thread John W. Krahn
John Ackley wrote: > Trying to split class C IPs into network and host parts. > > this works but I expected the host part in $2: > >print "<$bu>\n" if $debug; >if( $bu =~ /^((\d+\.){3})(\d+)$/ ) { >print "$1 $2 $3\n" if $debug; >} > > output: > <172.19.252

How to chek the nth column of a delimited file

2006-09-10 Thread benbart
Hi all, I have to re-process a delimited file but I only need to proceed records from the file that satisfy a specific condition. Can someone advise what is the best way to do this? For example, if I have this file here A~BB~CCC~DDD~~D~ A~BB~CCC~DDD~~D~ A~BB~CCC~DDD~~U~3

Re: Summary for mean/average calculation in perl

2006-09-10 Thread Chad Perrin
On Sun, Sep 10, 2006 at 07:12:08AM -0700, chen li wrote: > > 2)List::Util is "built-in" as of 5.8, and back > compatible to 5.5 > > use List::Util qw(sum); > > my $average = sum(@input) / @input; > > > 6)$mean = eval(join("+", @data)) / @data; > > Depending on how you understand Perl a

Re: Re: Re unexpected result

2006-09-10 Thread Tom Phoenix
On 9/10/06, John Ackley <[EMAIL PROTECTED]> wrote: perl -MCPAN just gave me the dreaded "Out of memory" and I have only a simple scan to perform and parse - at the moment I am leaning towards hacking it! You don't have to use the CPAN module to install things from CPAN itself, of course. In t

Re: Re unexpected result

2006-09-10 Thread John Ackley
Thanks, Tom! Tom's comment poses an interesting question: when to hack it or use a module? "For educational or experimental reasons, I hope, since you're writing your own low-level code instead of using a module." I find that perl is wonderful - it has thousands upon thousands of modules all

Re: Summary for mean/average calculation in perl

2006-09-10 Thread John W. Krahn
Rob Dixon wrote: > John W. Krahn wrote: >> chen li wrote: >> >>> 5) my $mean+=$_/@data [EMAIL PROTECTED]; >> >> That was not posted and it won't work correctly (see the NOTE at the >> end of >> the "Statement Modifiers" section of perlsyn.) > > Ruud posted it in the 'perl built in function for mea

Re: usage of grep and map

2006-09-10 Thread chen li
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > chen li wrote: > > > > --- Tom Phoenix <[EMAIL PROTECTED]> wrote: > > > >>The expression in a map is evaluated in a list > >>context. The list that > >>it returns is included in the result list. > > > >>The expression in a grep is a Boolean va

Re: usage of grep and map

2006-09-10 Thread John W. Krahn
chen li wrote: > > --- Tom Phoenix <[EMAIL PROTECTED]> wrote: > >>The expression in a map is evaluated in a list >>context. The list that >>it returns is included in the result list. > >>The expression in a grep is a Boolean value, so it's >>evaluated in a >>scalar context. If it's true, the co

Re: Re unexpected result

2006-09-10 Thread Igor Sutton
2006/9/10, John Ackley <[EMAIL PROTECTED]>: Trying to split class C IPs into network and host parts. this works but I expected the host part in $2: print "<$bu>\n" if $debug; if( $bu =~ /^((\d+\.){3})(\d+)$/ ) { print "$1 $2 $3\n" if $debug; } output: <

Re: Re unexpected result

2006-09-10 Thread Tom Phoenix
On 9/10/06, John Ackley <[EMAIL PROTECTED]> wrote: Trying to split class C IPs into network and host parts. For educational or experimental reasons, I hope, since you're writing your own low-level code instead of using a module. this works but I expected the host part in $2: print "

Re unexpected result

2006-09-10 Thread John Ackley
Trying to split class C IPs into network and host parts. this works but I expected the host part in $2: print "<$bu>\n" if $debug; if( $bu =~ /^((\d+\.){3})(\d+)$/ ) { print "$1 $2 $3\n" if $debug; } output: <172.19.252.130> 172.19.252. 252. 130 where did my

Re: output not in current directory

2006-09-10 Thread chen li
What is the code for this from the > window > > > promt(not within the script itself)? > > > > > > c:\>perl test.pl >1(this will save the result in > the > > > current directory. > > > How about saving the result to c:/perl/self/?) > > > > > > Thanks, > > > > > > Li > > > > Hi Li, > > > > Google

Re: usage of grep and map

2006-09-10 Thread chen li
--- Rob Dixon <[EMAIL PROTECTED]> wrote: > > > > > > #!C:/Perl/bin/perl.exe > > > > use warnings; > > use strict; > > use Data::Dump qw(dump); > > > > > > my @data=( > > [1,2,3], > > [4,5,6], > > [7,8,9] > > ); > > > > my @reverse_map=map{[reverse @[EMAIL PRO

Re: Summary for mean/average calculation in perl

2006-09-10 Thread Rob Dixon
Rob Dixon wrote: John W. Krahn wrote: chen li wrote: 5) my $mean+=$_/@data [EMAIL PROTECTED]; That was not posted and it won't work correctly (see the NOTE at the end of the "Statement Modifiers" section of perlsyn.) Ruud posted it in the 'perl built in function for mean' thread at 7:4

Re: Re: usage of grep and map

2006-09-10 Thread chen li
--- Tom Phoenix <[EMAIL PROTECTED]> wrote: > On 9/10/06, chen li <[EMAIL PROTECTED]> wrote: > > > So map function returns the transformed or changed > > elements but not the original ones and grep still > > returns the original ones? > > The only thing grep can return are the elements of > the

Re: Summary for mean/average calculation in perl

2006-09-10 Thread Rob Dixon
John W. Krahn wrote: chen li wrote: 5) my $mean+=$_/@data [EMAIL PROTECTED]; That was not posted and it won't work correctly (see the NOTE at the end of the "Statement Modifiers" section of perlsyn.) Ruud posted it in the 'perl built in function for mean' thread at 7:46 GMT this morning (10

Re: output not in current directory

2006-09-10 Thread Jen Spinney
On 9/10/06, Jen Spinney <[EMAIL PROTECTED]> wrote: On 9/10/06, chen li <[EMAIL PROTECTED]> wrote: > Hi all, > > When I run scripts I want the result saved to a > different directory instead of the current one on > window xp. What is the code for this from the window > promt(not within the script

Re: Re: usage of grep and map

2006-09-10 Thread Tom Phoenix
On 9/10/06, chen li <[EMAIL PROTECTED]> wrote: So map function returns the transformed or changed elements but not the original ones and grep still returns the original ones? The only thing grep can return are the elements of the original list, but it generally doesn't return all of them. Fo

Re: output not in current directory

2006-09-10 Thread Jen Spinney
On 9/10/06, chen li <[EMAIL PROTECTED]> wrote: Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\>perl test.pl >1(this will save the result in th

Re: output not in current directory

2006-09-10 Thread Rob Dixon
chen li wrote: Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\>perl test.pl >1(this will save the result in the current directory. How about

Re: usage of grep and map

2006-09-10 Thread Rob Dixon
chen li wrote: Hi all, Although I read the usage for grep and map using perldoc -f grep or map I don't think I really get the differences between them. I have a small data set: my @data=( [1,2,3], [4,5,6], [7,8,9] ); I want to reverse the elements in each ro

output not in current directory

2006-09-10 Thread chen li
Hi all, When I run scripts I want the result saved to a different directory instead of the current one on window xp. What is the code for this from the window promt(not within the script itself)? c:\>perl test.pl >1(this will save the result in the current directory. How about saving the result

Re: usage of grep and map

2006-09-10 Thread chen li
--- Tom Phoenix <[EMAIL PROTECTED]> wrote: > On 9/10/06, chen li <[EMAIL PROTECTED]> wrote: > > > Although I read the usage for grep and map using > > perldoc -f grep or map I don't think I really get > the > > differences between them. > > The expression in a map is evaluated in a list > cont

Re: Summary for mean/average calculation in perl

2006-09-10 Thread John W. Krahn
chen li wrote: > > --- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > >>chen li wrote: >> >>>6)$mean = eval(join("+", @data)) / @data; >>> >>>Depending on how you understand Perl and what >>progress >>>you are I prefer 6). >>Depending on how you understand Perl, 6 is the worst >>solution. > > Coul

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 tes

Re: usage of grep and map

2006-09-10 Thread Tom Phoenix
On 9/10/06, chen li <[EMAIL PROTECTED]> wrote: Although I read the usage for grep and map using perldoc -f grep or map I don't think I really get the differences between them. The expression in a map is evaluated in a list context. The list that it returns is included in the result list. The

usage of grep and map

2006-09-10 Thread chen li
Hi all, Although I read the usage for grep and map using perldoc -f grep or map I don't think I really get the differences between them. I have a small data set: my @data=( [1,2,3], [4,5,6], [7,8,9] ); I want to reverse the elements in each row only but not

Re: Summary for mean/average calculation in perl

2006-09-10 Thread chen li
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > chen li wrote: > > Dear all, > > Hello, > > > Thank for replying my post. Here is the summary of > all > > the posssible code lines: > > > > Q:If Perl has the short-cut/built-in function for > > calculating Mean/Average? > > > > my @data=(1,

Re: Summary for mean/average calculation in perl

2006-09-10 Thread John W. Krahn
chen li wrote: > Dear all, Hello, > Thank for replying my post. Here is the summary of all > the posssible code lines: > > Q:If Perl has the short-cut/built-in function for > calculating Mean/Average? > > my @data=(1,1,1); > > mean/average=(1+1+1)/3=1; > > A: > > No Perl built-in funct

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 h

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]

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 Per

Summary for mean/average calculation in perl

2006-09-10 Thread chen li
Dear all, Thank for replying my post. Here is the summary of all the posssible code lines: Q:If Perl has the short-cut/built-in function for calculating Mean/Average? my @data=(1,1,1); mean/average=(1+1+1)/3=1; A: No Perl built-in function for mean/average but there are several ways to

Re: splitting the line correctly

2006-09-10 Thread Xavier Mas i Ramón
A Diumenge 10 Setembre 2006 01:56, Robert Krueger va escriure: > Hi, > I bought 3 books a few days ago on Perl, and things are going well with > one exception. > > An example: > > @line = "this is a very long line word1+word2+word3 and it contines on and > on"; > > The object is to execute a spli

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]