I have a comma delimited file like this:
"field1","field 2","Some longer field 3 here","And some field 4"
.I want to ask my users how many fields there are and populate that to a 
scalar, then ask them what the field titles are and shove that input into 
an array.  Then I want to ask them which field (asking for the number, not 
the title) has a key value.  I want to then take that input, use it to make 
a hash of each record, then a hash of those hashes so that I have all the 
records.  I'm fine until that last step, and I keep thinking I've worked it 
out, and then I run into another snag.  Here's what I have so far.

use strict;

my($file1, $f1fnum, @f1fname, $f1namef, $f1key);

#First, get the path of the file that has the names that need to be compared.
#The first line prints the question, the second line assigns the typed 
response, less the newline
#to a variable name.

print "What is the path of the file that needs to be matched?  ";
chomp($file1 = <STDIN>);
open(FILE1,'$file1') || die "I can't seem to find that file.  Here's why: $!";

#Now, check to get information about the file itself.

print "\nHow many fields are there in this file? ";
chomp($f1fnum = <STDIN>);

print "\nPlease type the field names (no spaces) separated by commas. \n 
For example, Name, Address1, City, etc.: ";
chomp(@f1fname = <STDIN>);

print "\nWhich field (1, 2, 3, 4, etc.) has the name filed to be compared? ";
chomp($f1namef = <STDIN>);
--$f1namef;

print "\nWhich field (1, 2, 3, 4, etc.) has some unique identifier for each 
record? ";
chomp($f1key = <STDIN>);
--$f1key;

print "\nThat's all I need for file 1, but now I have some questions about 
the file you will be comparing to.\n";

my($i, %hfile1);
#Now, we'll need to load the file into two hashes of hashes.  I know that I 
will need to loop through line by
#line, so...
while (<FILE1>){
#Now, I know that I need to match each field with it's name from the array 
to make the inner hash.
#I also need to then add that to the outer hash, and start with the next 
line.  I just don't know how
#to do that part.

If this is confusing to anyone other than me, let me know and I will try to 
clarify if I can.  And, of course, if there is some better way to model 
this file so that I can compare it to another file, again, I'm quite happy 
to hear any criticism about that as well.  Thanks.

Reply via email to