I hope I am understanding your question correctly. This
little piece of code takes a string delimited by spaces,
splits it up into a list, and exits with a true flag if
any one element of the list contains exactly one letter
followed by exactly one digit.
use strict;
my $string = 'bar a2 b2 c3 d3 d4 a1 f2 f3';
my $flag = 0;
foreach(split(/\s+/, $string)) {
$flag++, last if /\w\d/;
}
print "foo's found in list\n" if $flag;
If you wanted to specify a list of foo's to match against,
such as only d4 or b2, you could try this instead . . .
use strict;
my @foos = qw(d4 b2);
my $string = 'bar a2 b2 c3 d3 d4 a1 f2 f3';
my $flag = 0;
foreach my $cand (split(/\s+/, $string)) {
foreach(@foos) {
$flag++, last if $cand =~ /$_/;
}
}
print "foo's found in list\n" if $flag;
Hope this helps,
Jeff
UPDATE: Oops, you wanted d4 AND b2 - luckily for me,
merlyn has got you covered . . .
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.