Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: the if statement

by broomduster (Priest)
on Sep 27, 2008 at 22:11 UTC ( #714066=note: print w/ replies, xml ) Need Help??


in reply to the if statement

This looks like homework, so here are some hints.

(keys %hash) is a list of the keys for %hash. The scalar assignment $input = (keys %hash) puts the number of keys into $input (which is probably not what you want to do). OTOH, to compare $input to each of the keys, you need to loop through the keys, comparing $input to each key. Since the keys (and the user input) are strings, you use eq to do the comparison.

Updated: Scrub the stupidity; no need to check everything; this is a hash, after all.


Comment on Re: the if statement
Select or Download Code
Replies are listed 'Best First'.
Re^2: the if statement
by eyepopslikeamosquito (Canon) on Sep 28, 2008 at 02:27 UTC
Re^2: the if statement
by FunkyMonk (Canon) on Sep 27, 2008 at 22:50 UTC
    you need to loop through the keys, comparing $input to each key
    That's what exists is for. In this case if ($hash{$input}) { ... } is probably good enough.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-07-08 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls