Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How do I read a line of text from a file into an array?

by ton (Friar)
on Jul 17, 2001 at 00:57 UTC ( [id://97176]=note: print w/replies, xml ) Need Help??


in reply to How do I read a line of text from a file into an array?

looks to me like you should be using hashes, not arrays. I'd do something like this:
use strict; open(HASH, "testhash.txt") || die; my $line = <HASH>; chomp $line; $line =~ s/'//g; my %hash = split(/,/, $line); print "\nEnter the keycode: "; chomp($line = <STDIN>); print "Keycode $line has the value $hash{lc($line)}\n" if ($hash{lc($l +ine)});
Note that this will not match superstrings of valid keycodes, which your code does. I'm fairly certain that this was not your intent :)

-Ton

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://97176]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-25 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found