in reply to Unable to Understand grep and hash use for prime no.
Do I understand correctly that for numbers where $is_prime{$_} is false, the cached value is overwritten by a (supposedly superfluous) evaluation of is_prime($_)?my %is_prime; @primes = grep { ( exists $is_prime{$_} and $is_prime{$_} ) or ( $is_prime{$_} = is_prime($_) ) } @numbers;
|
|---|