sub nonrepeating { my $word = shift || $_; my %chars; @chars{ split( //, $word)} = (); length($word) == keys %chars; } my @solutions; while (<DICT>) { chomp; push @solutions, $_ if length() == 15 and nonrepeating(); }
This uses the short-circuit behavior of and to only do the expensive nonrepeating() test if the word has fifteen characters. As a matter of style, some will object to the $_ default in sub nonrepeating, but I think pronouns fit right in there. This saves some memory over yours at runtime since only actual solutions are pushed.
After Compline,
Zaxo
In reply to Re: Coffee time quiz
by Zaxo
in thread Coffee time quiz
by perlmoth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |