Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: The following returns no value for $lang

by kilinrax (Deacon)
on Oct 26, 2000 at 22:35 UTC ( [id://38701]=note: print w/replies, xml ) Need Help??


in reply to The following returns no value for $lang

You are using references unnecessarily; a hash would work just fine. I suspect what you probably want is something more like this:
#!/usr/bin/perl -w use strict; open(LANGUAGES,"languages.txt") or die "cannot open languages.txt"; my $line; my %hash; foreach $line (<LANGUAGES>) { my ($language, $author) = split ', ', $line; $hash{$language} = $author; } my $lang; print "Enter a programming language: "; chomp ($lang = <STDIN>); if (exists $hash{$lang}) { print "$lang was originally developed by $hash{$lang}.\n"; } else { warn "Language not found!"; }

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-03-29 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found