I am trying to convert "Smith, A.B., Jones, C.D. and Doe, E.F." into: "Smith, A.B." "Jones, C.D." "Doe, E.F."
That is to say, I need to split on every other ','. I have code which works, but there must be a more elegant way.
Here is what I have:
#! /usr/local/bin/perl
#
use strict;
use warnings;
use diagnostics;
#
my @originators = ();
my $cellValue = "Smith, A.B., Jones, C.D. and Doe, E.F.";
# This could also be "Smith, A.B., Jones, C.D., Doe, E.F."
#
my @tempArray = split(m/,| and /, $cellValue); # split on ',' or ' and '
# Unfortunately, this splits too finely, so knit back together again
for (my $loop=0; $loop<@tempArray; $loop+=2)
{
$originators[$loop / 2] = $tempArray[$loop] . "," . $tempArray[$loop + 1];
### print STDERR "tempArray[$loop] = \"", $tempArray[$loop], "\"\n"; ### DEBUG ###
### print STDERR "tempArray[$loop+1] = \"", $tempArray[$loop+1], "\"\n"; ### DEBUG ###
print STDERR "originators[$loop/2] = \"", $originators[$loop/2], "\"\n"; ### DEBUG ###
}
#
exit(0);
I strip leading and trailing white space elsewhere, so that is not a problem.
Many thanks for any help you can give.
Regards, Martin
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
