In your second print statement, there is no "/" between LastName and the curly brace. You'll need to close it like this:
print @$ref{ qw/FirstName MiddleName LastName/ };
If that doesn't solve your problem, look into the way you are constructing each hashref in the first loop. Maybe the keys in @fields aren't correct? Data::Dumper will be your friend in times like these. Use it to peer inside @results.
Also, a side note, you may be able to simplify and/or speed up the parsing routine you have using DBD::CSV along with DBI. Not only is the underlying engine it uses faster than regexes, but it handles all the parsing details for you. Another benefit is it provides you a little less painful upgrade path in the future if you need to move to a relational database.
Here's an example of what you were doing, only using DBI:
#Connect to the data source
my $dbh = DBI->connect(
"DBI:CSV(RaiseError=>1,AutoCommit=>1,Taint=>1,ChopBlanks=>1):csv_sep
+_char=\t"
);
my $statement = q{
SELECT *
FROM filename
WHERE FirstName = ?
};
my $sth = $dbh->prepare($statement);
$sth->execute($value);
while(my $row = $sth->fetchrow_hashref) {
print @$row{ qw(FirstName MiddleName LastName) };
}
Make sure that the word "filename" inside $statement gets changed to whatever file you're parsing. You will need to rename the file so that it has no extension, as DBD::CSV requires this.
Update: I shouldn't have used SELECT * like above, this requests all the fields, not just what I need. In some cases using * in SQL can be very evil when you've got alot of records. The general rule of thumb is you should try to SELECT only those columns that are necessary. Sorry, my bad.
It should read like this:
my $statement = q{
SELECT FirstName
, MiddleName
, LastName
FROM filename
WHERE FirstName = ?
};
|