Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Text::CSV::Simple does a great job of ignoring the first column of each line (which is not needed)

Your code ignores the first two columns, because the columns are numbered from zero.

I don't quite understand your overall goal, but this should help:

#!/usr/bin/perl -w use strict; use Text::CSV::Simple; my $parser = Text::CSV::Simple->new; $parser->want_fields(1, 2, 3, 4); my @data = $parser->read_file(\*DATA); foreach my $line (@data) { if ($line->[0] =~ m/SMTP:/i) { print "here are the parts of the first column:\n"; my @parts_of_first_column = split(';', $line->[0]); foreach my $part (@parts_of_first_column) { print " * $part\n"; } } } __DATA__ "CN=MBX_MANA,OU= Mailboxes,DC=doman,DC=com",;sm;;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,

Which prints out:

here are the parts of the first column: * * * * X400:c=us\ * a= \ * p=domain\ * o=Exchange\ * s=MANAGER\

So Text::CSV::Simple splits up the CSV in a smart way, and then the code splits up the first (remaining) column by semicolons. From there on you should be able to test each part for the stuff you want.

($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print

In reply to Re: Best method of munging CSV data - using Text::CSV::Simple? by Cody Pendant
in thread Best method of munging CSV data - using Text::CSV::Simple? by billie_t

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-09-19 00:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found