Okay, so your question is basically "How do I edit a string of comma delimited email addresses"?

One way is to separate the data. Split the string on commas (assumes no email address have commas in them), then split each of those elements into outside <> and inside <>
Edit the data, then rebuild your string.

This seems to work:

#!/usr/bin/perl -w use strict; my $test='A <a@bob.com>, B <B@b.org>, Calcutta <O@thehorror.net>'; my @names = split /\s?,\s?/, $test; #split apart $_ = [split /\s(?=<)/, $_] for (@names); #make array refs of each # Above happily learned from merlyn foreach my $name (@names) { foreach (@{$name}){ print "--$_--"; } print "\n"; }
It outputs:
--A----<a@bob.com>-- --B----<B@b.org>-- --Calcutta----<O@thehorror.net>--

And of course, you can edit that as you wish. Of course, if you KNOW one element, it'd be better to use a hash

#!/usr/bin/perl -w use strict; my $test='A <a@bob.com>, B <B@b.org>, Calcutta <O@thehorror.net>'; my %names = split /,\s|\s(?=<)/, $test; #split apart foreach my $name (keys (%names)) { print "$name==$names{$name}\n"; }
This also works, and allows you to access (and modify) $names{Joe Schmoe}

Rebuilding your original list is even easier after you modify it.

my @names; while (my ($key, $value) = each %names){ push @names, "$key $value"; } print join ', ',@names;
Note that all of the above code assumes that:
  1. No email addresses or names have commas
  2. No names or email address have < beyond the wrapper around email addresses
  3. Your list always has the entries separated with a comma then a space
  4. Your names are always separated from your email addresses by a space.

In reply to RE: Re: Building an SQL query by swiftone
in thread Building an SQL query by despair

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.