billie_t has asked for the wisdom of the Perl Monks concerning the following question:
The valid info we want to extract is represented by the first line - the second column has smtp addresses that we want to grab, and associate with the third column (the username) and the final column (the server name). Eventually I want to achieve:"CN=MBX_MANA,OU= Mailboxes,DC=doman,DC=com",SMTP:Manager@domain.com;sm +tp:MBX_MANA@domain.com;FAX:MBX_MANA@domain.com;X400:c=us\;a= \;p=doma +in\;o=Exchange\;s=MANAGER\;,MBX_MANA,/o=Exchange Org/ou=First Adminis +trative Group/cn=Configuration/cn=Servers/cn=SERVER "CN=Guest,CN=Users,DC=domain,DC=com",,Guest,
user@server blah@smtpaddress user@server blah@smtp2address user2@server blah2@smtpaddress user2@server blah2@smtp2addressEach user can have a variable number of STMP addresses. The second line of the original data posted above is an example of an invalid line that we would like to skip (there are no smtp addresses).
I think I can figure out the regexps (mostly) to grab the data I want, such as SMTP: but not FAX: or X400: addresses. Text::CSV::Simple does a great job of ignoring the first column of each line (which is not needed), and stashing the others somewhere else, using this code:
That appears to be the easy part. I need to achieve the remaining steps:my $parser = Text::CSV::Simple->new; $parser->want_fields(2, 3, 4); my @data = $parser->read_file($infile);
2. Ensure that all the SMTP addresses extracted match up to the correct userid.foreach my $line (@data) { chomp; if $line =~ /SMTP:/i {do stuff} }
The main problem is, by reading into a single-dimension array, I think that I'm losing the "columns" which associate the SMTP addresses with the correct userid and server. I simply don't know enough about arrays or hashes (or Perl, other than the fact it's by far the best tool for the job) to structure the data in the appropriate way so that I can extract what I want.
Any help would be appreciated. The input files will not be larger than 2MB, and the whole thing will be running on up-to-date kit (so reading into memory should not be a problem). And I'm sorry I couldn't come up with more code - not having a clue about appropriate structure is not helping me. It may be that Text::CSV::Simple is not right for the job, but I couldn't quite get to grips with the syntax of Text::CSV_XS, for example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best method of munging CSV data - using Text::CSV::Simple?
by Cody Pendant (Prior) on Feb 08, 2006 at 05:39 UTC | |
by billie_t (Sexton) on Feb 08, 2006 at 06:15 UTC | |
by Cody Pendant (Prior) on Feb 08, 2006 at 06:20 UTC | |
|
Re: Best method of munging CSV data - using Text::CSV::Simple?
by jZed (Prior) on Feb 08, 2006 at 06:00 UTC | |
by billie_t (Sexton) on Feb 08, 2006 at 06:23 UTC | |
by Scott7477 (Chaplain) on Feb 05, 2007 at 23:02 UTC | |
|
Re: Best method of munging CSV data - using Text::CSV::Simple?
by billie_t (Sexton) on Feb 09, 2006 at 00:59 UTC | |
by Scott7477 (Chaplain) on Feb 06, 2007 at 00:11 UTC |