Greetings all,
Well, some help that merlyn supplied in the past encouraged me to use map and some regex magic (magic to me, I'm sure basics to everyone else) to solve a problem, everything worked exactly as I hoped until I tried to match a numeric range - doh! can't regex a numeric range. Here's what I have, I've transformed my data and am working with it in this form: A1:123:C and I need to see if it matches any of an array of data in the form A0-7:123:C where 0-7 is a range. What I would like to know is if there is a way to match the :123:C from each expression, and if so, send the test case and match off to a sub to check for a range match of the A1 to A0-7 portion. I could do
my @array = (A0-7:123:C, B8-15:456:D);
my $check = A4:123:C;
foreach my $line(@array){
my $subline = join(":", (split(":", $line))[1,2]);
#not sure is that join/split thing works just consider this whateve
+r it takes to get the 123:C into $subline
my $subcheck = #again whatever it takes to get 123:C
if ($subcheck =~ /$subline/){
$match = &checkRange($check, $line);
}
}
I'm looking for something more efficient, though. I have to test about 20-40 cases against 30-40 possible matches, and do this about 400 times, in a somewhat time sensitive environment, so effiency is key.
UPDATE: I'm not looking for the sub to determine if some number is in the range, I can do that. I'm wondering if there is a better approach than the code that I've listed?
UPDATE PART 2:
Well, I finally got as close to what I wanted to do as I think I'm going to get. I had to take care of a little tunnel vision, that I fear a shared with you in the way I presented my problem, but here is what I came up with:
my @array = (A0-7:123:C, B8-15:456:D);
my $check = A4:123:C;
my $test = join(' ', @array);
my $find = join(':', ((split(':',$check))[1,2]));
my @found = ($test =~ m/\b\w\d+\-\d+:$find\b/g);
This way I still have my $check value, and a possible match in @found, and I can send these to a sub to check if the A4 part is in the range of the A0-7 part of the matching value. Thanks to those who were part of my problem solving process.
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.