<?xml version="1.0" encoding="windows-1252"?>
<node id="927642" title="Re: Hangman - Hanging with Friends" created="2011-09-24 06:55:24" updated="2011-09-24 06:55:24">
<type id="11">
note</type>
<author id="540414">
jwkrahn</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;&lt;c&gt;
# Scrabble distribution
our %letter_distribution = qw(
  a 9  b 2  c 2  d 4
  e 12 f 2  g 3  h 2
  i 9  j 1  k 1  l 4
  m 2  n 6  o 8  p 2
  q 1  r 6  s 4  t 6
  u 4  v 2  w 2  x 1
  y 2  z 1
) ;
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
You never use this variable anywhere so why is it here?
&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;



&lt;blockquote&gt;&lt;i&gt;&lt;c&gt;
  sort { score_word($a) cmp score_word($b) }
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
&lt;c&gt;score_word()&lt;/c&gt; returns a numeric value so that should be:
&lt;/p&gt;
&lt;c&gt;
  sort { score_word($a) &lt;=&gt; score_word($b) }
&lt;/c&gt;
&lt;p&gt;
And if you used a [wp://Schwartzian Transform] you wouldn't have as much overhead on all those subroutine calls.
&lt;/p&gt;
&lt;c&gt;
# search for matching words
my @possible_words =
    map $_-&gt;[ 1 ],
    sort { $a-&gt;[ 0 ] &lt;=&gt; $b-&gt;[ 0 ] }
    map length() == length( $word_pattern ) &amp;&amp; pattern_word( $word_pattern, $_ ) ? [ score_word( $_ ), $_ ] : (),
    @dictionary;
&lt;/c&gt;&lt;br /&gt;&lt;br /&gt;



&lt;blockquote&gt;&lt;i&gt;&lt;c&gt;
sub score_word {
  my ($word) = @_ ;
  my $points = 0 ;
  my @letters = split //, $word ;
  $points += $letter_points{$_} foreach @letters ;
  return $points ;
}
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
You could use [mod://List::Util]::sum and reduce that to:
&lt;/p&gt;
&lt;c&gt;
use List::Util qw/ sum /;

sub score_word { sum( @letter_points{ split //, $_[ 0 ] } ) }
&lt;/c&gt;&lt;br /&gt;&lt;br /&gt;




&lt;blockquote&gt;&lt;i&gt;&lt;c&gt;
  my %deny_letters = map { $_ =&gt; 1 } split(//, $pattern) ;
  my @p = split //, $pattern ;
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
Why [doc://split] the same thing twice:
&lt;/p&gt;
&lt;c&gt;
  my @p = split //, $pattern ;
  my %deny_letters = map { $_ =&gt; 1 } @p ;
&lt;/c&gt;
</field>
<field name="root_node">
927629</field>
<field name="parent_node">
927629</field>
</data>
</node>
