Hey guys,
You provided me some expert help the last question I asked here, and now that I've been beating my head against a wall for hours now, I figured I'd see if anyone can help me out.
I have a script that accesses an SMTP folder, downloads an email with a CSV attached, parses the CSV, and sends emails to anyone listed in the CSV. Sounds fairly straight-forward, right? The CSV is in this format:
contactname,email,city
Luke,luke@test.com,Kansas City
My problem is the client REFUSES to send a standard CSV file each time. He changes the header names (from "city" to "country"), capitalizes them, rearranges them, etc. I simply can't sit with the guy and force him to use a correctly formatted CSV file, so I am forced to idiot-proof my script. Now he wants several people to use the same mailing system, and I need a way to dynamically sniff the headers in the CSV.
I am using the Tie::Handle::CSV module to do most of my parsing, but my headers are hard-coded like this:
my $fh = Tie::Handle::CSV->new($csvfile, header => 1,
+ open_mode => "< :encoding(ISO 8859-1)");
while (my $csv_line = <$fh>) {
$lookup_email = $csv_line->{'email'} ...
I have just started working with Perl, so bear with me as this might be an easy question...
How do I dynamically display what the names of the headers are? I am already telling the module that the headers are located on line 1, but now I need to write each of them to their own string (or throw them into an array) so I can use them later.
Sorry for being such newb :). Thanks!