Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Find words that contain at least "msixpodual"
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Text::Table;
my @flags = split //, "msixpodual";
my %flags;
@flags{@flags} = ();
my %words;
while (my $word = <>) {
chomp $word;
my $cp = $word;
my $remaining = '';
my $score = 0;
for my $flag (@flags) {
if ($cp =~ s/$flag//i) {
} else {
$remaining .= $flag;
# Skip non-serious candidates
next if length($cp) > 0;
if ($score) {
$words{$word} = {
score => $score,
remaining => $remaining,
my @order = sort {
($words{$b}->{score} <=> $words{$a}->{score}) or
length($a) <=> length($a)
} keys %words;
my @tr;
for my $word (@order) {
push @tr => [
my $tb = Text::Table->new(
"Score", "Word", "Remaining"
print $tb;

This comment has been minimized.

Copy link

@tamias tamias commented Feb 22, 2011

Oops: length($a) <=> length($a)
(Not that it matters; if two words have the same score, then they have the same length as well. In fact, the score /is/ the length!)


This comment has been minimized.

Copy link
Owner Author

@avar avar commented Feb 22, 2011

There's a much improved version of this on perl5-porters now. This was just something I hacked up and is full of bugs and misfeatures :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.