library (random numbers)

2007-08-07 Thread Amichai Teumim
Does this make any sense? Here is the script again: #!/usr/bin/perl use strict; use warnings; require 'obj13-lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; And here is the library: sub sumIt{ my $total; $total += $_ for @_; warn "@_ was empty, total undefined!\n" i

Re: library (random numbers)

2007-08-07 Thread Amichai Teumim
Yeah I think it was a comment. I removed it now. Thanks ;) Jeff Pang wrote: > -Original Message- > >> From: Amichai Teumim <[EMAIL PROTECTED]> >> Sent: Aug 6, 2007 10:34 AM >> To: "Mr. Shawn H. Corey" <[EMAIL PROTECTED]> >> Cc: beginn

Re: library (random numbers)

2007-08-07 Thread Martin Barth
On Tue, 07 Aug 2007 11:23:05 +0300 Amichai Teumim <[EMAIL PROTECTED]> wrote: > > Line 11 n obj13-lib.pl is: > > (last index). Double check > > I don't know what could be wrong with this syntax, as I have never used > these commands before. I thought it migh need a curly, but I get the > same er

Re: library (random numbers)

2007-08-07 Thread Jeff Pang
-Original Message- >From: Amichai Teumim <[EMAIL PROTECTED]> >Sent: Aug 6, 2007 10:34 AM >To: "Mr. Shawn H. Corey" <[EMAIL PROTECTED]> >Cc: beginners@perl.org >Subject: Re: library (random numbers) > >I just renamed it to obj13-1.pl from script

library (random numbers)

2007-08-07 Thread Amichai Teumim
Line 11 n obj13-lib.pl is: (last index). Double check I don't know what could be wrong with this syntax, as I have never used these commands before. I thought it migh need a curly, but I get the same error. Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> I get: >> >> Not enough argument

Re: library (random numbers)

2007-08-07 Thread Amichai Teumim
So that makes sense. (last index). Double check shouldn't even be there. I must have incompletely removed the comment. So I should just delete it or comment it out? Chas Owens wrote: > On 8/6/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: > snip > >> sub sumIt{ >> my $total; >> $total += $

Re: library (random numbers)

2007-08-07 Thread A. Teumim - Netgear Support
So this is what I have now in my library: sub sumIt{ my $total; $total += $_ for @_; warn "@_ was empty, total undefined!\n" if !defined $total; } sub avg(@) { my @arr = @_; my $arrSize = scalar(@arr); #(last index). Double check; return sumIt(@arr) / @arr; } 1; Why is return sumIt(@arr

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: I get: Not enough arguments for index at obj13-lib.pl line 11, near "index)" Compilation failed in require at obj13-1.pl line 6. What is this index error? Go to line 11 in obj13-lib.pl and check its syntax. -- Just my 0.0002 million dollars worth, Shawn "For the

Re: library (random numbers)

2007-08-06 Thread Chas Owens
On 8/6/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: snip > sub sumIt{ > my $total; > $total += $_ for @_; > warn "@_ was empty, total undefined!\n" if !defined $total; > } snip This will return nothing useful. You need a return statement after the warn. > sub avg(@) > { > my @arr = @_; > m

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
I just renamed it to obj13-1.pl from script.pl So it looks now like this: #!/usr/bin/perl use strict; use warnings; require 'obj13-lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; and the library I renamed to: obj13-lib.pl and now looks like this: sub sumIt{ my $total;

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
No it was commented out. Now it's changed. I still don't know how to use it. What would a good way to test it be? echo 1234 | ./script.pl obviously won't do much. I wad told ./obj13-1.pl < Paul Lalli wrote: >> Yes, it would have, if that's what you had. But you didn't. You had >> the line: >> #

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 9:03 am, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote: > Paul Lalli wrote: > > Yes, it would have, if that's what you had. But you didn't. You had > > the line: > > #require 'lib.pl' > > > That is, you had the line commented out. A commented out line does > > nothing at all. > > > Paul

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 9:03 am, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote: > Paul Lalli wrote: > > Yes, it would have, if that's what you had. But you didn't. You had > > the line: > > #require 'lib.pl' > > > That is, you had the line commented out. A commented out line does > > nothing at all. > > > Paul

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: No it was commented out. Now it's changed. I still don't know how to use it. What would a good way to test it be? echo 1234 | ./script.pl obviously won't do much. I wad told ./obj13-1.pl < What the heck is obj13-1.pl? To test your script you need a list of numbers one

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
When I do this, I get : ./script.pl < line 3. #!/usr/bin/perl #require 'script.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> ./script.pl | echo 1234 >> >> Or is this nonsensical? Very very new to Perl. > > This is actually sh

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Paul Lalli wrote: Yes, it would have, if that's what you had. But you didn't. You had the line: #require 'lib.pl' That is, you had the line commented out. A commented out line does nothing at all. Paul Lalli Actually, in the post I replied to it was: #require 'script.pl'; The OP seems t

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 7:56 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: > Mr. Shawn H. Corey wrote: > > Amichai Teumim wrote: > >> #!/usr/bin/perl > >> #require 'lib.pl'; > > require 'lib.pl'; > >> @userArray = ; > >> $sum = sumIt(@userArray); > >> print $sum; > > > If the sub sumIt() is in the file lib.pl,

Re: library (random numbers)

2007-08-06 Thread Paul Lalli
On Aug 6, 6:52 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: > This is pure educational. I want to understand how this all works. > > So after follow your comments my script.pl looks like this: > > !/usr/bin/perl This shebang is incorrect. Specifically, you're missing the "sh" part of "shebang":

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
I thought that require 'lib.pl'; was telling Perl where to find it. Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> When I do this, I get : >> >> ./script.pl <> 1234 >> 5678 >> 90 >> EOD >> >> Undefined subroutine &main::sumIt called at ./script.pl line 7, >> line 3. >> >> #!/usr/bin/perl

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
Hi Paul This is pure educational. I want to understand how this all works. So after follow your comments my script.pl looks like this: !/usr/bin/perl use strict; use warnings; require 'lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; AND my library like this: sub sumIt(

Re: library (random numbers)

2007-08-06 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: When I do this, I get : ./script.pl < line 3. #!/usr/bin/perl #require 'script.pl'; require 'lib.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; If the sub sumIt() is in the file lib.pl, you have to tell perl where to find it. -- Just my 0.0002 m

Re: library (random numbers)

2007-08-03 Thread Paul Lalli
On Aug 3, 6:03 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: > After some friendly input from yitzle I might have moved further with > my library. > > This is my script. > > script.pl > > #!/usr/bin/perl Get into the habbit of using use strict; use warnings; in all of your scripts. You will be g

Re: library (random numbers)

2007-08-03 Thread Chas Owens
On 8/3/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: snip > sub sumIt(@) snip > sub avg(@) snip Ack prototypes! They don't do what you think they do. Don't use them until you have read http://library.n0i.net/programming/perl/articles/fm_prototypes and understand it fully. Prototypes are very us

Re: library (random numbers)

2007-08-03 Thread Mr. Shawn H. Corey
Amichai Teumim wrote: ./script.pl | echo 1234 Or is this nonsensical? Very very new to Perl. This is actually shell: echo 1234 | ./script.pl Try: ./script.pl

library (random numbers)

2007-08-03 Thread Amichai Teumim
After some friendly input from yitzle I might have moved further with my library. This is my script. script.pl #!/usr/bin/perl #require 'lib.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; And this is my library according to yitzle: sub sumIt(@) { my $total = 0; $total += $_

Re: library (random numberS)

2007-07-27 Thread Andy Greenwood
On 7/27/07, yitzle <[EMAIL PROTECTED]> wrote: > I was under the impression that "average" meant mean. correct. Average is the common term for mean. In fact, reading the pages linked above, they do imply (without stating explicitly) that the three terms describe different calculations. I can't thi

Re: library (random numberS)

2007-07-27 Thread yitzle
I was under the impression that "average" meant mean. sub sumIt(@) { my $total = 0; $total += $_ for (@_); return $total; # This line might not be needed... } sub avg(@) { my @arr = @_; my $arrSize = @arr; # scalar(@arr) is the array size - or one less (last index). Double check retur

Re: library (random numberS)

2007-07-27 Thread Chas Owens
On 7/27/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: snip > What do I add here to calculate the average of the numbers? snip Which average do you want (common ones are mean, mode, and median)? Try looking them up on Wikipedia: * http://en.wikipedia.org/wiki/Mean#Arithmetic_mean * http://en.wikip

library (random numberS)

2007-07-27 Thread Amichai Teumim
OK. I think I moved further. So this is my library. ub sumIt(){ @functionArray = @_; foreach $line(@functionArray){ $functionSum += $line; } return $functionSum; } 1; What do I add here to calculate the average of the numbers? thanks Amichai -- To unsubscribe, e-mail: [EMAIL

library (random numbers)

2007-07-27 Thread Amichai Teumim
OK I figured most of this out I think. I want to create a library that contains a function which takes in an array of numbers (random numbers). This function will then calculate the average of these numbers, the total of all these numbers added together, and a new array of numbers which is the oth