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)
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 += $_ for @_;
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 arguments for
-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.pl
So it looks now like this:
#!/usr/bin/perl
use
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 error.
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: beginners@perl.org
Subject: Re: library (random numbers)
I just renamed
Does this make any sense?
Here is the script again:
#!/usr/bin/perl
use strict;
use warnings;
require 'obj13-lib.pl';
my @userArray = STDIN;
my $sum = sumIt(@userArray);
print $sum;
And here is the library:
sub sumIt{
my $total;
$total += $_ for @_;
warn @_ was empty, total
Amichai Teumim wrote:
When I do this, I get :
./script.pl EOD
1234
5678
90
EOD
Undefined subroutine main::sumIt called at ./script.pl line 7, STDIN
line 3.
#!/usr/bin/perl
#require 'script.pl';
require 'lib.pl';
@userArray = STDIN;
$sum = sumIt(@userArray);
print $sum;
If the sub
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 = STDIN;
my $sum = sumIt(@userArray);
print $sum;
AND my library like this:
sub
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 EOD
1234
5678
90
EOD
Undefined subroutine main::sumIt called at ./script.pl line 7, STDIN
line 3.
#!/usr/bin/perl
#require
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:
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 = STDIN;
$sum = sumIt(@userArray);
print $sum;
If the sub sumIt() is in the file lib.pl, you have to tell
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
When I do this, I get :
./script.pl EOD
1234
5678
90
EOD
Undefined subroutine main::sumIt called at ./script.pl line 7, STDIN
line 3.
#!/usr/bin/perl
#require 'script.pl';
@userArray = STDIN;
$sum = sumIt(@userArray);
print $sum;
Mr. Shawn H. Corey wrote:
Amichai Teumim wrote:
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 EOD
What the heck is obj13-1.pl?
To test your script you need a list of numbers
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 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 Lalli
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 EOD
Yet that doesn't seem to work either.
Mr. Shawn H. Corey wrote:
Paul Lalli wrote:
Yes, it would
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 = STDIN;
my $sum = sumIt(@userArray);
print $sum;
and the library I renamed to: obj13-lib.pl and now looks like this:
sub sumIt{
my
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 = @_;
my $arrSize =
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
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 EOD
1234
5678
90
EOD
--
Just my 0.0002 million dollars worth,
Shawn
For the things we have to learn before we can do them,
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 greatful
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 = STDIN;
$sum = sumIt(@userArray);
print $sum;
And this is my library according to yitzle:
sub sumIt(@)
{
my $total = 0;
$total
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
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
*
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
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
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
return
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 think
Hello, I need to generate two random numbers. One should be a 1, 2,
or 3, and the other should be a 1 or 2. How can I do that?
- Grant
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
Grant wrote:
Hello,
Hello,
I need to generate two random numbers. One should be a 1, 2,
or 3,
int( rand 3 ) + 1
and the other should be a 1 or 2.
int( rand 2 ) + 1
perldoc -f int
perldoc -f rand
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
On 3/16/07, Grant [EMAIL PROTECTED] wrote:
Hello, I need to generate two random numbers. One should be a 1, 2,
or 3, and the other should be a 1 or 2. How can I do that?
- Grant
That depends on your needs. The rand function creates decent quality
pseudo-random numbers (it calls srand
On 3/16/07, Chas Owens [EMAIL PROTECTED] wrote:
snip
my $num = int rand 3 + 1;
snip
oops, that should be
my $num = int rand(3) + 1;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
Chas Owens wrote:
On 3/16/07, Grant [EMAIL PROTECTED] wrote:
Hello, I need to generate two random numbers. One should be a 1, 2,
or 3, and the other should be a 1 or 2. How can I do that?
That depends on your needs. The rand function creates decent quality
pseudo-random numbers (it calls
a
better interface to /dev/random and /dev/urandom. It also has the
ability to generate good random numbers on systems that don't have
them.
* http://search.cpan.org/~vipul/Crypt-Random-1.25/lib/Crypt/Random.pm
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL
On 3/16/07, John W. Krahn [EMAIL PROTECTED] wrote:
snip
my $num = int rand 3 + 1;
That will return either 0, 1, 2 or 3. The addition has higher precedence.
snip
Yeah, I saw that after I posted. That is what I get for posting untested code.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For
Another way,
my @c = (1,2,3); my @d = (1,2);
print join '',$c[int rand @c],$d[int rand @d];
This could generate arbitrary random string other than the numbers of 1 2 3
or 1 2.
ie,the original contents could be:
my @c = qw(a,b,c);
my @d = qw(4,5,6);
Hello, I need to generate two random
installed openssh on the machine, and the entropy
daemon that comes with it. Ever since then, perl is unable to generate
random numbers. There are 40 files in my pictures directory, so my
program picks a number between 1 and 40, the result is ALWAYS 29. If
I write a small program to simply pick
I know some people may complain and say I don't know what
I'm talking about, but I read somewhere recently (while
working on a dice function for my IRC bot) that srand
is no longer necessary. You might try removing that line
from your code and see what errors you get (I doubt it
will fix the
the same sequence of random numbers thereafter.
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Stefan Johnson wrote:
I know some people may complain and say I don't know what
I'm talking about, but I read somewhere recently (while
working on a dice function for my IRC bot) that srand
is no longer necessary. You might try removing that line
from your code and see what errors you get
Rob Anderson wrote:
Hi Guys,
According to my bookshelf, from 5.004 onwards srand uses a seed that's
that's reasonably difficult to guess. Prior to that, it used time(). It
does seem as if the seed it being set the as the same value each time. Could
your program be being cached some where?
was working
fine, until I installed openssh on the machine, and the entropy
daemon that comes with it. Ever since then, perl is unable to
generate random numbers. There are 40 files in my pictures
directory, so my program picks a number between 1 and 40, the result
is ALWAYS 29. If I write a small
Dr. Poo wrote:
On Saturday 01 February 2003 03:18 pm, R. Joseph Newton wrote:
Jamie Risk wrote:
Remember the principle of KISS.
Ahem..excuse me; What is the principle of KISS? Thanks. :)
Keep It Simple, Stupid!
/R
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional
On Fri, Jan 31, 2003 at 03:51:04PM -0500, Jamie Risk wrote:
I'm looking around, and I see Quantum::Entanglement which looks like
overkill; I'd like to generate, 8/16/32 bit random numbers.
- Jamie
rand() seems like what you're looking for.
perldoc -f rand
--
Michael
[EMAIL PROTECTED]
http
Jamie Risk wrote:
I'm thinking I could open up /dev/urandom/ but that hardly seems portable.
Hi Jamie,
Remember the principle of KISS.
#!/usr/bin/perl -w
use strict;
my $bits = $ARGV[0];
my $Random = int (rand(2**$bits));
print $Random\n;
Joseph
--
To unsubscribe, e-mail: [EMAIL
On Saturday 01 February 2003 03:18 pm, R. Joseph Newton wrote:
Jamie Risk wrote:
I'm thinking I could open up /dev/urandom/ but that hardly seems
portable.
Hi Jamie,
Remember the principle of KISS.
Ahem..excuse me; What is the principle of KISS? Thanks. :)
Also, for the rand script
I'm looking around, and I see Quantum::Entanglement which looks like
overkill; I'd like to generate, 8/16/32 bit random numbers.
- Jamie
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
te, 8/16/32 bit random numbers.
- Jamie
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Quantum::Entanglement which looks like
overkill; I'd like to generate, 8/16/32 bit random numbers.
Perl's random number function is called rand.
perldoc -f rand
my $num = int rand 2 ** $bits;
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL P
Hi ,
Is there any one who can help me make a randon numer generator
Any help will be appreciated.
Thanks
Sushil Prabhakar
Cybernet Communications Inc.
Suite 207
20 Amber Street
Markham, Ontario
L3R 5P4
Tel: (905) 947 1801
Fax:(905) 947 1802
Hi Sushil,
perldoc -f rand
You can also look at the Math::Random and Math::TrulyRandom modules on the
CPAN.
Cheers,
Kevin
On Tue, Apr 24, 2001 at 02:58:16PM -0700, sushil ([EMAIL PROTECTED]) spew-ed forth:
Hi ,
Is there any one who can help me make a randon numer generator
Any help will
53 matches
Mail list logo