On Mar 1, 2004, at 6:14 PM, Stuart White wrote:


That's not really accurate. What was said to that:

@list = "@list";

Creates a joined string of elements and replaces the
list with that one
item.  It's perfectly reasonable to stringify an
array, without
altering the array's contents:

print "@list\n";


I'm not sure I understand.

Try looking at some sample code:


my @list = qw(Apple Orange Banana);

print "@list\n"; # prints Apple Orange Banana; @list is NOT modified.

@list = "@list";
# the above basically means:
# @list = "$list[0] $list[1] $list[2]";
# since there is only one item on the right, it goes it $list[0] and the other
# indexes are cleared


print "@list\n"; # prints Apple Orange Banana, but list only has one string now

Now what I'd like to do to test whether or not I
have
a prime number is to get at each element in
@primelist, and use the modulus operator on each
element against each element in @list.  For
example:
$primelist[0] % $list[0]
$primelist[0] % $list[1]
$primelist[0] % $list[2]
$primelist[1] % $list[0]
$primelist[1] % $list[1]
$primelist[1] % $list[2]
$primelist[2] % $list[0]
$primelist[2] % $list[1]
$primelist[2] % $list[2]        

and if the result doesn't equal 0 for every test
except for against itself, then I want to unshift
it
onto @primelist.

I thought I'd do this with nested foreach loops,
but
that didn't seem to work. Any ideas?

Define "didn't seem to work"? On second thought, just post that nested foreach and let us help you fix it.

James


Ok, I went with for loops. As above, I want to get the modulus of numbers in one array by comparing the numbers of another array. It's not doing what I expect it to. I'm not sure if the first loop is really running either. What am I doing wrong? (Does that question make sense?)

It makes perfect sense, yes, but I'm still missing one piece of information, the broken code you would like fixed. As I said in my last message, "...just post that nested foreach and let us help you fix it."


Also, I'm getting an error: Use of uninitialized value
in modulus (%) at primeNumbers.pl line 40, <STDIN>
line 1.
Illegal modulus zero at primeNumbers.pl line 40,
<STDIN> line 1.
What do those errors mean exactly?  Thanks.

That's not an error, it's a warning. It means one of the variables used in the % operation at line 40 doesn't have anything in it. That test isn't really testing anything and that's probably why your program isn't running correctly. Perl just thought you would like to know, since you asked for warnings. Handy, eh?


James


-- 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