fenners has asked for the wisdom of the Perl Monks concerning the following question:
The script behaves as if @list is a single line of text rather than an array. Yet if I simply copy and paste the line of text into @list like so:
@list=('key1,value1','key2,value2','key3,value3','key4,value4');
then I can do arrayish things with it. Here is my script:
Any help would be much appreciated because I'm clearly missing some vital point here!#testhash.txt has a single line of text that reads: #'key1,value1','key2,value2','key3,value3','key4,value4' open(HASH,"testhash.txt"); $line=(<HASH>); chomp $line; @list=($line); @list=('key1,value1','key2,value2','key3,value3','key4,value4'); print "here is \@list:\n"; print $list[0]; print $list[3]; print "\nEnter the keycode:"; chop ($find=<STDIN>); foreach (@list) { ($keycode,$keyvalue)=split /,/; #split up the array elements if ($find=~/$keycode/i) { print "Keycode $keycode has the value $keyvalue \n"; } }
|
|---|