scain has asked for the
wisdom of the Perl Monks concerning the following question:

Hello Fellow Monks,

I return to coding after several months off and it seems like
I have forgotten everything I ever knew. As a warmup project,
I wanted to make a simple parser that would take free-form
address data and generate V-card formatted data, with the
help of user input. This was supposed to be an easy, one off
script, that I have now been working on for a few hours.

Here is how it is suppposed to work: Read through a file one
line at a time and present its contents at STDOUT. The user
then selects an action, either to split the line on commas,
thus breaking up a city and state for later categorization,
or the user selects what category the item belongs in. After the user selects a category, the array that holds the data (possibly from a previous split) is shifted, and then it goes through the loop again. Seems straight forward enough. (As a side note: yes I really do want to do it this way, because it really is free-form: some addresses are typical, three or four lines, some are all mushed together in one line, comma delimited.)

But, when a file has this as its contents Medina, OH, and Medina is properly categorized as a city, and the shift is done, initially, $la[0] holds "OH", but when it
gets to the bottom of the loop, it is mysteriously undef. I don't see how or why, but I suspect that it is my rusty skills causing me to miss something. Please take a look at the code below and let me know what I am missing.

You are using many different if statements, so you can go through more than one. This is important because if your else statement.

$response is tested to be equal to be 2,3,4, and 5, at which point, you have action, and your value's printed. Then it continues to be tested for 6,7,8,9, and 1. After the one, you have an else. Since response equals 5 and not 1, the else is executed, shifting the array again.

Change all the ifs but the first in the series to elsifs, and it should work. ;-)

2. Just to clarify: The first time through the loop, $la[0] contains "Medina, OH", then I do a
split /\,\s*/, $la[0] and assign it back into @la, so now $la[0] should contain "Medina" and
$la[1] should contain "OH". Second time through the loop, I select "5", $la[0] gets assigned into the hash, and I shift, which should bump "Medina" out, and put "OH" at $la[0].

I think your problem lies in the shift @la.in your code as $la[0] is taken from the from being set and $la[1] is now $la[0].. You seem to be adding things to the array and then removing them ala shift. So when you get to the end you have nothing in the array.

update: I changed it so it made more sense, as when I reread it the third time, I seemed to have been babbling.