in reply to Huge simple problem
and in a loop this simple I would just use $_my @searchTexts = split (/and|or/i,$query); foreach my $text (@searchtexts) { $text =~ s/^\s+//; $text =~ s/\s+$//; print "$text\n"; }
or reduce it even further with a map and a join (depends on circumstance, if I'm the not only maintainer I'd probably use the above version)foreach (split /and|or/i,$query) { s/^\s*(.*?)\s*$/$1/; print "$_\n"; }
all the above code is untested.print join("\n",map {/^\s*(.*?)\s*$/;$1} split(/and|or/i,$query)) . "\ +n";
of course at this point you can skip the whole split and use:print join("n\",split(/\s*(?:and|or)\s*/,$query)) . "\n";
A final note, all these will fail horribly if your data has and/or imbedded in words. ie world. You probably want to split on /\s+(?:and|or)\s+/ or /\s*\b(?:and|or)\b\s*/$query =~ s/\s*(?:and|or)\s*/\n/g; print "$query\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Huge simple problem
by dsheroh (Monsignor) on Aug 06, 2009 at 00:04 UTC | |
by Anonymous Monk on Aug 06, 2009 at 01:00 UTC | |
by Anonymous Monk on Aug 06, 2009 at 01:01 UTC | |
by dreadpiratepeter (Priest) on Aug 06, 2009 at 04:07 UTC | |
|
Re^2: Huge simple problem
by Anonymous Monk on Aug 05, 2009 at 23:07 UTC |