CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Searching...

 



Pro_4
User

Apr 27, 2001, 9:17 AM

Post #1 of 3 (311 views)
Searching... Can't Post

Hey would this work...

$word = <STDIN>; #takes in the info the user typed
%dictionary = ( dog => ' Bark ' , cat => ' Meow ' );
print %dictionary {$word}; # this is the part i want to # know if it would work.

Is this method a viable way of recalling information?
Would taking in the $word and applying it in the %dictionary call up the right information if dog was typed in? Thanks for the help.

People Engrossed by a Reliable Language


japhy
Enthusiast

Apr 27, 2001, 10:49 AM

Post #2 of 3 (309 views)
Re: Searching... [In reply to] Can't Post

First, you need to remove the newline character from the end of the string the user input:


Code
chomp($word = <STDIN>);

Then, please read the perldata documentation (there's a link to the Perl documentation at the left of the page), which will show you how to use Perl variables.


Code
if (exists $dictionary{$word}) { 
print "I have an entry for '$word': $dictionary{$word}\n";
}

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


Pro_4
User

Apr 27, 2001, 1:04 PM

Post #3 of 3 (305 views)
Re: Searching... [In reply to] Can't Post

Alrightie thanks a lot :)

People Engrossed by a Reliable Language

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives