There are a number of ways to do this. Easy way is with cascading "greps", like in my first example. Regex is wonderful at "or" but the "and" kind of thing can be complex in the syntax.
I would suggest one of the below formulations. Tweak to suit your needs.
oops, my brain is really out to lunch today...sorry.see update
#!/usr/bin/perl -w
use strict;
my @input = ("Exception : CEX",
"Exception : TEX",
"abc def ljj");
print grep{/TEX/} grep{/^\s*Exception/}@input;
print "\n";
print grep{/Exception/ && /TEX/}@input;
print "\n";
print grep{/^\s*Exception.*? TEX/}@input;
__END__
prints:
Exception : TEX
Exception : TEX
Exception : TEX
#!/usr/bin/perl -w
use strict;
my @input = ("Exception : CEX",
"Exception : TEX",
"abc def ljj");
print grep{!/CEX/}grep{/^\s*Exception/}@input;
print "\n";
print grep{/Exception/ && !/CEX/}@input;
print "\n";
__END__
prints:
Exception : TEX
Exception : TEX
I wouldn't get overly concerned about performance unless this code is going to be executed lots of times. Clarity should be the first priority.
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.