in reply to Parsing a csv file from Exchange

If you are only interested in pulling out the SMTP email address from the field, you could get it to work this way:
# ... up to this point, # you must have read 1 line from the file ... # and (for sake of example) the email field saved in into $email_field + variable. my @emails; while ($email_field =~ m/SMTP:([^\%]+)\%/g) { # validate matched email first... (as per UPDATE) push @emails, $1; # add email address to the list } # @emails array now contains all SMTP email addresses # found in the field.
Here, I look for any sub-string in the field bounded with string 'SMTP' on the left and '%' character on the right. Option /g allows regular expression to pick successive occurances of a matched string (on every loop cycle). You could read more on this and many other features of Perl regular expressions here.

UPDATE: thanks jeffa. The reason I used the while loop is to also possibly include some email address validation inside the loop for every match. Therefore, only 'correct' email addresses would go in the array. Of course, a one-liner would work better if no such thing was required or validation occurred later on the @emails array.

_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/;$_=&#91"ps -e -o pid | "," $2 | "," -v "," "]`@$_`?{print" ++ $1"}:{print"- $1"}&&`rm $1`;print"\n";}

Replies are listed 'Best First'.
(jeffa) 2Re: Parsing a csv file from Exchange
by jeffa (Bishop) on May 21, 2002 at 00:12 UTC
    No need for the while loop and push, and you want to drop the last % sign in case the field in question is the last one:
    my @emails = $email_field =~ m/SMTP:([^\%]+)/g;
    Note to cajun: you do know about the Text::CSV CPAN modules, correct?

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Thanks to all. This works fine as long as SMTP is the first address listed in $email_field. Unfortunately Bill doesn't always put SMTP first. (see my example above). If anything other than SMTP is first, this breaks.