Use perl to match a value from one file and use it to lookup values in another file using the skills below:

In the last step, you learned and practiced reading from a file and loading an array.

Your job: In this step, you will code the full lookup from one file through an association key file and into another file, displaying the results of the associated match. This is complex code, so be sure to use step-wise refinement, and print statements to expose the program logic as you debug.

Start with the result of the last step. You now have a list of keys from the first file that match the search word. Test once more to be sure this works.

Add another for each loop that reads through the key array and finds all matches to the key. You will need a for each loop, that also loops through the assocation file. Here is some detailed logic suggestion though there are other solutions:

// create a new key array for the associated keys

for each $gamekey (@gamekeys){ // this holds the game keys you extracted from matching lines

// read every line in the association file using while

// if a line matches the key in the position in should (use =~ /pattern/ to match to either the right or left side of a row : ex /.*,$gamekey.*/

// when you find a match, extract the associated key using the split command

// put the associated key into the associated key array

Test this when it is completed before coding the next step.

Now you have a list of all the associated keys. You can read through them looking for matches using a similar method to the prior loop. When you find a match, split it into parts and print the information in the matched row.

Test this all in perl. You now know how to use arrays and while loops and pattern matching and split to navigate through your files.

Note: Later, you will hook this up to the script that enters a search word through html (your cgi script). It may help to place all this code into a subroutine so it can be more easily dropped into your cgi script.