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>) {      ($id,$name) = 
split(/!/,$line,2); $info{$id} = $name; } print "Enter id:"; $key = <STDIN>; print 
("ID: $key  NAME : $info{ $key} \n");
 ***** costumer.dat ***** 001!Paul 002!Leo 003!Nick  





 
                   

Reply via email to