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 = ? };

In reply to Re: Re: getting the right stuff by dkubb
in thread getting the right stuff by malaga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.