I don't understand all the business about scoring, but at least this gets the expected fields for the given input strings. Perhaps you can use it as a point of departure to achieve your true goals.
c:\@Work\Perl\monks>perl -wMstrict -le
"use Test::More 'no_plan';
use Test::NoWarnings;
;;
use Data::Dump qw(dd);
;;
use List::MoreUtils qw(uniq);
;;
my @list = (
'set abcde-efghi 12345',
'set abcde-ijkl 12345',
'clr abcde-efghi+123',
'clr abcde-ijkl 12345',
);
;;
my @expected_substrings = (
'set', 'clr', ' abcde-', 'efghi', 'ijkl', ' 12345', '+123',
);
;;
my $rx_fld1 = qr{ [[:alpha:]]{2,} }xms;
my $rx_fld2 = qr{ \s [[:alpha:]]{2,} - }xms;
my $rx_fld3 = qr{ [[:alpha:]]{3,} }xms;
my $rx_fld4 = qr{ [\s+] [[:digit:]]{2,} }xms;
;;
my (@flds1, @flds2, @flds3, @flds4);
for my $str (@list) {
my $parsed =
my ($fld1, $fld2, $fld3, $fld4) =
$str =~ m{
\A ($rx_fld1) ($rx_fld2) ($rx_fld3) ($rx_fld4) \z
}xms;
die qq{'$str' parse failed} unless $parsed;
;;
push @flds1, $fld1;
push @flds2, $fld2;
push @flds3, $fld3;
push @flds4, $fld4;
}
;;
my @got_substrings = uniq @flds1, @flds2, @flds3, @flds4;
dd \@got_substrings;
;;
is_deeply \@got_substrings, \@expected_substrings,
'extracted list ok';
"
["set", "clr", " abcde-", "efghi", "ijkl", " 12345", "+123"]
ok 1 - extracted list ok
ok 2 - no warnings
1..2
Note: uniq is also in List::Util in up-to-date versions of Perl; I'm testing under version 5.8.9.
Update: It occurs to me that the uniq-ifying step should be done on each sub-set individually before the sub-sets are combined together. This could be done with a
my @got_substrings = map { uniq @$_ } \(@flds1, @flds2, @flds3, @flds4);
statement. The output list produced is the same.
Give a man a fish: <%-{-{-{-<
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, 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, 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.
|
|