Is this headed in the right direction?
Meaning does this code produce the output that you want? (given your single test case)...Program specifications are hard to write and I think the best way forward here is just refinement by example.
#!/usr/bin/perl -w
use strict;
my $input = '"non$volatile display" and ((timer oR count$3 Or display)
+ near5 hour).ccls. NOT (LCD).ab.';
my @omissions = qw(terms and or not with near same xor adj);
my $omit = join("|",@omissions);
$input =~ s/\..*?\.//g;
$input =~ s/$omit//ig;
my @searchterms = ($input =~ m/".+?"|[a-zA-Z][\w\$]+/gi);
print "@searchterms";
#prints:
#"non$volatile display" timer count$3 display hour LCD
update:
-I think that you mean for these .xyz. terms to be deleted?
-Above doesn't allow for terms in @omissions to be taken absolutely literally. I need to look in Larry's book for the syntax. But this does show a dynamic regex. Also probably need to take into account that omit words should be on boundaries (whole words - not words within words, the \b - look in Larry's book)
-Running substitute operations can take some time as the string is modified after each one, but this may or may not matter time-wise.
-The question right now: is this is "right" output? I mean for this given single input case?
As a general approach, I try to break these complex things into multiple easier steps. Get the right output, then tweak it if performance is not adequate.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.