in reply to Parsing a sentence based on array list
use Modern::Perl; use Regexp::Assemble; my $line = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. +'; my @array = ( 'ipsum', 'sit amet', 'elit' ); my $ra = Regexp::Assemble->new; $ra->add(@array)->anchor_word(1)->re; say $ra->as_string; # just for educational purposes $line =~ s/$ra//g; say join "\n", split /\W+/, $line;
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|