Hello Monks,
I just have a quick question and I can't believe I can't figure it out on my own. I'm working on a simple word game, and what I need perl to do is open up a dictionary file (I've already limited the dictionary wordlist to 6 letter words) and then based on a given 6 character input, output all words from the dictionary list that can be made from those letters, of course in any order.
What I have right now just for testing the code snippet...
use strict;
use warnings;
my $input = <STDIN>;
my @inputarray = split('',$input);
my $file = 'wordlist.txt';
open(INFO, $file);
my @lines = <INFO>;
close(INFO);
my $tacobell;
foreach $tacobell (@lines) {
if ($tacobell =~ /$inputarray[0]$inputarray[1]$inputarray[2]$input
+array[3]$inputarray[4]$inputarray[5]/) {
print $tacobell;
}
}
exit();
After having read through about 15 regex tutorials, I'm sure there's an easy way to do this, I just can't figure it out. I think my code looks for the sequence of characters in that order ... I just need it from any order.
Also, I know there are some different ways of formatting regex to decrease cpu time where you don't have to recalculate certain things, so hopefully if there's a solution to this problem it'll be somewhat cpu friendly :)
I'd appreciate any help yall can offer!
Thanks,
Alan
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.