OK, so it was an interesting problem:

use strict; use warnings; use DBI; my $dbfile = 'D:\Delme~~\demo.db'; unlink $dbfile; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","",""); $dbh->do (qq{CREATE TABLE Demo (rowid INTEGER, old VARCHAR(9), new VAR +CHAR(3))}); my @testData = ( ['ABFD-1234' => 'AAA'], ['ABFD-178G' => 'BBB'], ['F2HB-9401' => 'AAA'], ['ZDDR-00W5' => 'DDD'], ['D7*D-48*6' => 'EEE'], ['*7RD-4896' => 'FFF'], ['D7RD-489*' => 'GGG'], ); my @old = map {$_->[0]} @testData; my @new = map {$_->[1]} @testData; my $sth = $dbh->prepare (qq{INSERT INTO Demo (old, new) VALUES (?, ?)} +); my $entries = $sth->execute_array ({}, \@old, \@new); $sth = $dbh->prepare (qq{SELECT old, new FROM Demo WHERE old LIKE ?}); $sth->execute ('%*%'); my @candidates = @{$sth->fetchall_arrayref ()}; for my $target ('D7PD', 'D7RD', '4897', '4876') { for my $candidate (map {$_->[0]} @candidates) { my @parts = split '\*', $candidate; my @rParts = reverse map {scalar reverse $_} @parts; my $str = $target; my $rStr = reverse $target; eval { matchPart($str, $_) || return for @parts; return !length $str; } or eval { $str = ''; rMatchPart($rStr, $_) || return for @rParts; return ! length $rStr; } or next; print "Matched '$target' against '$candidate'\n" if !length $s +tr; } } sub matchPart { my ($str, $match) = @_; $match = substr $match, 0, length $_[0]; return 1 if $_[0] =~ s/$match.?//; } sub rMatchPart { my ($str, $match) = @_; $match = substr $match, 0, length($str) - 1 if length $str; return 1 if $_[0] =~ s/.?$match//; }

Prints:

Matched 'D7PD' against 'D7*D-48*6' Matched 'D7RD' against 'D7*D-48*6' Matched 'D7RD' against '*7RD-4896' Matched 'D7RD' against 'D7RD-489*' Matched '4897' against 'D7RD-489*'

Only marginally tested. There are lots of edge cases that may be problematic, but maybe it's a hint in a useful direction.

Update: removed an edge case.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

In reply to Re: Partial Searches Against Multiple Wildcards by GrandFather
in thread Partial Searches Against Multiple Wildcards by p_jacobson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.