Also, this might help you understand what is going on with
exists $is_prime{$_} and $is_prime{$_}
Run the code to see the differences between exists(), defined and true. See if you can understand the warnings this code gives.
#!/usr/bin/perl use strict; use warnings; use feature qw/ say /; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my %hash; $hash{'A'} = 1; $hash{'B'} = 0; $hash{'C'} = -1; $hash{'D'} = undef; say Data::Dumper->Dump([\%hash], ['*hash']); for (qw/ A B C D E /) { say "Key: $_ Val: $hash{$_}"; say exists $hash{$_} ? ' exists' : ' does not exist'; say defined $hash{$_} ? ' defined' : ' not defined'; say $hash{$_} ? ' true' : ' false'; say '- -' x 20; } __END__
In reply to Re: Unable to Understand grep and hash use for prime no.
by 1nickt
in thread Unable to Understand grep and hash use for prime no.
by shankonit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |