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:
It outputs:#!/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"; }
--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
This also works, and allows you to access (and modify) $names{Joe Schmoe}#!/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"; }
Rebuilding your original list is even easier after you modify it.
Note that all of the above code assumes that:my @names; while (my ($key, $value) = each %names){ push @names, "$key $value"; } print join ', ',@names;
In reply to RE: Re: Building an SQL query
by swiftone
in thread Building an SQL query
by despair
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |