Sorry, I should have said. I'm writing a program to find prime numbers, and
what I want it to do is go from 0 to 200 and divide each number by all other
numbers. So I want say, 50 to be divided by 1 to 50, but to stop when it
finds a modulus. If it were a prime number, it would be divided by
everything between 1 and itself, and no modulus would be found. Any
suggestions?

Thanks

Joel
----- Original Message ----- 
From: "David le Blanc" <[EMAIL PROTECTED]>
To: "Joel" <[EMAIL PROTECTED]>; "Perl Lists" <[EMAIL PROTECTED]>
Sent: Wednesday, February 25, 2004 5:58 PM
Subject: RE: Is there an etc. command in perl?


> -----Original Message-----
> From: Joel [mailto:[EMAIL PROTECTED]
> Sent: Thursday, 26 February 2004 7:53 AM
> To: perl
> Subject: Is there an etc. command in perl?
>
> Is there an et cetera type command in perl? Specifically,

That's part of the Perl 7 - DWIM spec.

You may have to wait until easter though.

In the mean time.

> while (1) {
>     my $num = shift @numarray;
>     if ($num % 2==0) {
>
> and if the modulus of 2 is 0, find the modulus of 3 and so
> on. Can anyone
> give me some suggestions?
>

If I read this correctly, you want to skip the contents of
the numarray until you find a number who's modulus 2 is zero, and
do something with it.  Once you find one, you change the rules and
are now looking for a number who's modulus 3 is zero, then 4 etc?

my $mymod = 2;
for my $num ( @numarray ) {
if( $num % $mymod == 0 ) {
$mymod ++;

<do something here with $num>
}
}

Hope that helps.

PS. DWIM stands for 'Do What I Mean'.

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


Reply via email to