in reply to Comparing two arrays
Hi gilthoniel,
Welcome to the Monastery.
As already hippo and marinersk given you the algorithm to achieve your result, they missed to tell you How to check a number is divisible by another number.
To check if a number is divisible by another number use the modulus operator, %:
if ($num % $divisor) { # does not divide cleanly } else { # does. }I hope you have read the perlintro, So here i am giving you the code skeleton
#array declaration my @array1 = (....); my @array2 = (....); my ($num,$divisor); foreach $num (array contains dividend) # this loop is for iterator on +e by one { foreach $divisor (array contains divisor) # this loop checks f +irst array elements array divisible by the second array element { if ($num % $divisor) { # does not divide cleanly print "$num is not divisible by $divisor\n"; } else { # does. print "$num is divisible by $divisor\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing two arrays
by GrandFather (Saint) on Feb 21, 2015 at 03:55 UTC | |
by Athanasius (Archbishop) on Feb 21, 2015 at 04:35 UTC |