blob: 06240b226a1a1a7dddf03db7f8730bf3b3c8c971 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use Syntax::Construct qw{ // /r };
sub pangrams {
my ($dictionary) = @_;
my $pangram = "";
open my $in, '<', $dictionary or die $!;
chomp( my @words = <$in> );
my $missing = join "", 'a' .. 'z';
while ($missing) {
my $word = @words[ rand @words ];
# Only consider words that introduce a new char.
if ($word =~ /[$missing]/) {
$pangram .= "$word ";
$missing =~ s/[$word]//g;
}
}
return $pangram =~ s/ $//r
}
my $dictionary = shift // 'dictionary.txt';
say pangrams($dictionary);
|