my @words = gather {
for =(open '/usr/share/dict/words' err die) {
.=chomp;
next if /<-[a-z]>/;
/$re/ and take { word => $_, score => %scores{ .letters }.sum };
}
} ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html
> Does this make sense?
>
> my @words = gather {
> for =(open '/usr/share/dict/words' err die) {
> .=chomp;
> next if /<-[a-z]>/;
> /$re/ and take { word => $_, score => %scores{ .letters }.sum };
> }
> } ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };
With some effort I managed to understand _which_ sense it should make up
to this:
> } ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I mean: everything of what is gather()ed gets 'piped' into sort() which
sorts according to C<< { .<score> } >>. But what are the other args to it
supposed to mean? (Sorry for being dense!)
Michele
--
> i need to know what type of math and how much math a surgeon uses.
How about asking what type of surgery and how much surgery
a mathematician uses?
- Robin Chapman in sci.math
Since I sent the message, I learned that if you want to sort with
multiple criteria, the first argument should be an arrayref of closures.
So what I should have written is:
==> sort [ { .<score> } is descending, { .<word>.length }, { .<word> } ];
And it's easier to write if a simple numeric minus is used:
==> sort [ { -.<score> }, { .<word>.length }, { .<word> } ];
This makes sort sort by score first, but if two words score equally,
word length will become important (score with as few letters as
possible, because there's a greater chance of succeeding within the time
limit). If the lengths are also equal, it sorts alphabetically, so
that words beginning with the same letter are grouped together.
The other problem with this that = binds tighter than ==> does. Once you
start with pipes you probably want to stick with pipes:
gather {...} ==>
sort {...} ==>
my @words;
or
my @words <==
sort {...} <==
gather {...};
or just go back to the tried and true:
my @words =
sort {...}
gather {...};
Larry