I try to write a program that reads a file with two fields.The first field is a
costumer ID and the second is the costumer name by using " ! " as a seperator between
2 fields. Store costumer ID as the key and the costumer name as value into a hash.
My code is below, I have a problem that $info{ $key} does not show the value. What is
the problem ? How to change it?
Thank you.
***** myfile.pl *****
$filename ="costumer.txt";
open(FILE,$filename ) or die ("can not open file : $filename");
while ($line = <FILE>)
{
$line =~ s/\s+/ /g;
($id,$name) = split(/!/,$line,2);
$info{$id} = $name;
}
print "Enter id:";
$key = <STDIN>;
print ("ID: $key NAME : $info{ $key} \n");
***** costumer.dat ******
001!test1
002!test2
003!test3