in reply to Help with substitution - - 15 Characters from the left
I didn't bench this against substr and index, that might be more efficient, and I now this code could be compressed a bit but I thought this was a fairly clear way to write a sample.use strict; use warnings; my $max = 4; #Largest expected index. while (<DATA>) { s/#.*$//; #Clear out the comments chomp; my @foo = split /,/; my $company = $foo[1]; #prime a variable with a company name if ($#foo > $max) { #If there are more elements than the ma +x... my $range = (scalar @foo) - $max; #Get the top of the range $company = join '+', @foo[1..$range]; #The company name is in +a slice } print "$company\n"; #do whatever with the data. } __END__ client,ABC Company, jwilkens,jdoe,mdeart #this one is fine client,Cornell,Thayil,Cameron & Sheppard, LLC, klivingston,amarison,ps +erton #thi s one is not client,Doe,Smith & Randall, Inc, jwaters,pfloyd,jjoplin #this one is n +ot
Ira,
"So... What do all these little arrows mean?"
~unknown
|
|---|