[EMAIL PROTECTED] wrote:

$field = "Search, This is part of the code.";

## We need to split by spaces. The issue is that the comma comes along.

local(@words) = split('\s+', $field);
foreach $word (@words) {
if ($word =~ /Search/i) {
$word =~ s/[,\]\)\}]\b//;
$word =~ s/\b[,\]\)\}]//;
push(@new_array, $word);
last;
}
}


This code removes the comma. But I am puzzeled. I thought that the first line
$word =~ s/[,\]\)\}]\b//; would delete the comma.
Yet it was the second line that did it.
$word =~ s/\b[,\]\)\}]//;


The comma is at the end of the word, before the boundary. Shouldn't the first line have gottne rid of it.




\b matches the word-nonword or nonword-word boundary. This point is between the 'h' and the ',' in 'Search,'.
The first substitution would match ',abc', for example.



Won't be easier to split on [,\]\}\s]+? Like:

$field = "Search, This is part of the code.";
my @words =  split(/[,\]\}\s]+/,$field);
print join('|',@words); # prints: Search|This|is|part|of|the|code.


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to