blob: 1aab116d4d5407d01561251d9eb30e38ef68d21f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#You are given a file containing a list of words (case insensitive 1 word per
#line) and a list of letters. Print each word from the file that can be made
#using only letters from the list. You can use each letter only once (though
#there can be duplicates and you can use each of them once), you don’t have to
#use all the letters. (Disclaimer: The challenge was proposed by Scimon Proctor)
use strict;
use warnings;
my ($filepath, $letters) = @ARGV;
my $regexp = join('|', split(//, $letters));
open(my $file, '<', $filepath);
while(my $cl = <$file>) {
my $count = () = $cl =~ m/$regexp/g;
$count >= (length($cl) - 1) ? print $cl : 0;
}
close $file;
|