Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Unable to Understand grep and hash use for prime no.

by 1nickt (Canon)
on Aug 04, 2015 at 06:16 UTC ( [id://1137337]=note: print w/replies, xml ) Need Help??


in reply to Unable to Understand grep and hash use for prime no.

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__
The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1137337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-18 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found