and to complete the suite - a version using DBI. Note that there is a "cheat" here in that the first line of the sample data has been omitted and, due to the # at the start of the header line the data field's name is '# Date'.

use strict; use warnings 'all'; use DBI; # Create the sample file open outFile, '>', 'sample.csv'; print outFile
'Date Time client-ip Client-hostname Partner-Name Serve +r-hostname server-IP Recipient-Address Event-ID MSGID +Priority Recipient-Report-Status total-bytes Number-Recipien +ts Origination-Time Encryption service-Version Linked-MSG +ID Message-Subject Sender-Address 2005-9-10 0:0:16 GMT - - - storming - Someoneg@ao +l.com 1027 2433A69xxxxxxxxxxxxxxxx795006DB02DADF78@storming.Dom +ain.name1 0 0 11927 1 2005-9-10 0:0:16 GMT 0 - + c=US;a= ;p=AMSCAN;l=storming-050910000016Z-212788 Fw: Hey Ugly l +ine expansion and re-offer EX:/O=org/OU=Site/CN=RECIPIENTS/CN=Ause +r - 2005-9-10 0:0:16 GMT - - - storming - c1r3ai4g@ao +l.com 1019 2433A690xxxxxxxxxxxxxxxx5006DB02DADF78@storming.Doma +in.name1 0 0 11927 1 2005-9-10 0:0:16 GMT 0 - + - Fw: Hey Ugly line expansion and re-offer - - 2005-9-10 0:0:16 GMT - - - storming - c1r3ai4g@ao +l.com 1025 2433A6xxxxxxxxxxxxxxxx95006DB02DADF78@storming.Domai +n.name1 0 0 11927 1 2005-9-10 0:0:16 GMT 0 - +- Fw: Hey Ugly line expansion and re-offer - - 2005-9-10 0:0:16 GMT - - - storming - c1r3ai4g@ao +l.com 1024 2433A690Fxxxxxxxxxxxxxxxx6795006DB02DADF78@storming. +Domain.name1 0 0 11927 1 2005-9-10 0:0:16 GMT 0 +- - Fw: Hey Ugly line expansion and re-offer - - 2005-9-10 0:0:17 GMT - - - storming - c1r3ai4g@ao +l.com 1033 2433Axxxxxxxxxxxxxxxx428E5EE4C6795006DB02DADF78@stor +ming.Domain.name1 0 0 11927 1 2005-9-10 0:0:16 GMT +0 - - Fw: Hey Ugly line expansion and re-offer Auser@Doma +in.name - 2005-9-10 0:0:17 GMT - - - storming - c1r3ai4g@ao +l.com 1020 2433A69xxxxxxxxxxxxxxxx95006DB02DADF78@storming.Doma +in.name1 0 0 11927 1 2005-9-10 0:0:16 GMT 0 - + - Fw: Hey Ugly line expansion and re-offer Auser@Domain.name + -
'; close outFile; # The real sample code my $dbh = DBI->connect(qq{DBI:CSV:csv_sep_char=\\\t}) or die "Cannot connect: " . $DBI::errstr; my $sth = $dbh->{'csv_tables'}->{'info'} = { 'file' => 'sample.csv'}; $sth = $dbh->prepare("SELECT * FROM sample.csv") or die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); while (my $row = $sth->fetchrow_hashref) { print("$row->{'Date'}, $row->{'Time'}, $row->{'Recipient-Address'}, +$row->{'Message-Subject'}, $row->{'Sender-Address'}, \n"); } $sth->finish(); $dbh->disconnect();

Prints:

2005-9-10, 0:0:16 GMT, Someoneg@aol.com, Fw: Hey Ugly line expansion a +nd re-offer, EX:/O=org/OU=Site/CN=RECIPIENTS/CN=Auser, 2005-9-10, 0:0:16 GMT, c1r3ai4g@aol.com, Fw: Hey Ugly line expansion a +nd re-offer, -, 2005-9-10, 0:0:16 GMT, c1r3ai4g@aol.com, Fw: Hey Ugly line expansion a +nd re-offer, -, 2005-9-10, 0:0:16 GMT, c1r3ai4g@aol.com, Fw: Hey Ugly line expansion a +nd re-offer, -, 2005-9-10, 0:0:17 GMT, c1r3ai4g@aol.com, Fw: Hey Ugly line expansion a +nd re-offer, Auser@Domain.name, 2005-9-10, 0:0:17 GMT, c1r3ai4g@aol.com, Fw: Hey Ugly line expansion a +nd re-offer, Auser@Domain.name,

Perl is Huffman encoded by design.

In reply to Re: Extracting data from each line that matches a email address from a Log file (Tab delimited) by GrandFather
in thread Extracting data from each line that matches a email address from a Log file (Tab delimited) by Motomo94

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.