I am writing a script which will return distribution lists, their owners and their members. The file that I am parsing for this info is a .CSV file.

Here's what I've got so far:
#!/usr/bin/perl -w use strict; use Text::CSV; my $file = "/home/trix/Desktop/thisone.CSV"; my ($line, $key1, $key2, $test, $key3, @field, $members, $owner); my $count = 0; my $csv = Text::CSV->new(); open IN, "$file" or die "Can't open $file: $!\n"; while ($line = <IN> ){ chomp $line; $csv->parse($line) ; @field = $csv->fields; $key1 = $field[1]; $key2 = $field[2]; $key3 = $field[3]; ++$count; if ($key1 =~ s/^\\\~//) { print "List: $key1\n"; } if ($key2 =~ /\/o\=NETC\/ou\=(.*)\/cn\=Recipients\/cn\=(.*)/g) { $owner = $2; } else { $owner = "ssesar"; } print "Owner: $owner\n"; ($members) = ($key3 =~ /\=(.*)\%/g); ^^^^^^^^^^^^^^^^ # problematic code print "Members: $members\n\n"; print "############################################\n\n"; } print "Boston: $count lists\n
This will print, for instance:
############################################ List: Prod Dev SP Owner: NONE Members: Boston/cn=Recipients/cn=jdye%/ou=San Francisco/cn=Recipients +/cn=onisbett%/ou=Boston/cn=Recipients/cn=acorneau%/ou=Boston/cn=Recip +ients/cn=kfleming%/ou=Boston/cn=Recipients/cn=amiller%/ou=Boston/cn=R +ecipients/cn=rcrow%/ou=Boston/cn=Recipients/cn=tgoshco%/ou=San Franci +sco/cn=Recipients/cn=ldixon ############################################ List: Prod Dev IT+CR+ME Owner: NONE Members: San Francisco/cn=Recipients/cn=medelstein%/ou=Boston/cn=Reci +pients/cn=thodes%/ou=San Francisco/cn=Recipients/cn=gdistasi%/ou=Bost +on/cn=Recipients/cn=staylor%/ou=Boston/cn=Recipients/cn=drico%/ou=Bos +ton/cn=Recipients/cn=kkarrman%/ou=Boston/cn=Recipients/cn=tgoshco%/ou +=San Francisco/cn=Recipients/cn=rscaife ############################################
My question is, how can I extract only the member's names from the string of data after Members:?

It seems to me that the way to approach this problem is to match everything between "=" and "%". Or, maybe there's a better way to parse CSV data??

If it helps, the CSV file that I am using can be found here.

In reply to Matching every instance of text between two characters by Tuna

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.