Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I really don't know the requirements for your application.
I have taken an imperfect attempt at it below.

I did come close to your output for "s." but not exactly.
My output for "a." is wildly off from what you show.

I downloaded your DB file to a local file to make my testing faster.
I don't think that makes any difference.

I would like more text to describe what you want to have happen.

#!/usr/bin/perl use strict; use warnings; my @words; open my $fh, '<', 'EuroScrabbleWordList.txt' or die "can't open word l +ist $!"; foreach (<$fh>) { tr/\r\n//d; tr/A-Z/a-z/; next if /\s/; # dirty way of removing comments push @words, $_; } close $fh; ############################################ my $tiles = 'a.'; # print all words with 2 letters that contain "a" print "\nMATCHES FOR: $tiles\n"; my @m = find_matches($tiles); print "\n@m\n"; $tiles = 's.'; # print all words with 2 letters that contain "s" print "\nMATCHES FOR: $tiles\n"; @m = find_matches($tiles); print "\n@m\n"; $tiles = 'a.a'; #print all words with letters that contain 2 a's print "\nMATCHES FOR: $tiles\n"; @m = find_matches($tiles); print "\n@m\n"; ############################################ sub find_matches { my $pattern = shift; my $max_chars = length $pattern; my @matches; $pattern =~ s/\W+//g; #delete the dots my $raw_letters = $pattern; my $regex = ""; $regex .= "[$raw_letters].?" for (1..length $raw_letters); print "$regex\n"; foreach my $word (@words) { next if (length ($word) > $max_chars); push (@matches, $word) if $word =~ /$regex/; } return @matches; } __END__ MATCHES FOR: a. [a].? aa ab ad ae ag ah ai al am an ar as at aw ax ay ba da ea fa ha ja ka l +a ma na pa ta ya za MATCHES FOR: s. [s].? as es is os sh si so st us MATCHES FOR: a.a [aa].?[aa].? aa aah aal aas aba aga aha aia aka ala ama ana aua ava awa baa caa faa + maa
UPDATE:
I don't claim that my code is a general solution to your problem.
In fact, I think that many enhancements are necessary! This was just minimal code to answer some simple questions.

In terms of algorithms, let's start with something simple:
for "s.":

You say: as es is os sh si so I say: as es is os sh si so st us
I am completely unable to understand why st and us should be missing from the output? Please explain.

In reply to Re: Problem with regex wildcard operator (.)...? by Marshall
in thread Problem with regex wildcard operator (.)...? by sbrothy

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found