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!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.