Perl-Sensitive Sunglasses | |
PerlMonks |
Re^3: Stupidest Prime Number detector ever!!by johngg (Canon) |
on Jun 23, 2021 at 21:37 UTC ( [id://11134218]=note: print w/replies, xml ) | Need Help?? |
my @odds = map { $_ % 2 != 0 } @array; That's not going to do what you think. Consider the following:-
The alternating blanks and ones are registering the FALSE and TRUE results of the expression in the map, which essentially has a one to one relation between input on the right and output on the left. What you should be using instead is grep which filters input, only passing to the left those items for which the expression is TRUE.
Note also that you could dispense with the != 0 as the expression $_ % 2 will evaluate to either 0 or 1.
I hope this is helpful. Cheers, JohnGG
In Section
Seekers of Perl Wisdom
|
|