From bc48f4a394d64745da87660004d7ec6e67e7b4e1 Mon Sep 17 00:00:00 2001 From: LapVeesh Date: Sun, 21 Apr 2019 11:11:48 +0300 Subject: Added simple answer to advanced challenge --- challenge-004/veesh-goldman/perl5/ch-02.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 challenge-004/veesh-goldman/perl5/ch-02.pl diff --git a/challenge-004/veesh-goldman/perl5/ch-02.pl b/challenge-004/veesh-goldman/perl5/ch-02.pl new file mode 100755 index 0000000000..9a5fdefee6 --- /dev/null +++ b/challenge-004/veesh-goldman/perl5/ch-02.pl @@ -0,0 +1,27 @@ +#! /usr/bin/perl + +my $usage = <<"EOF"; +USAGE: +$0 letters [file] + + letters - a string consisting of the letters to filter by + file - the name of a file to check for words. If ommited, checks STDIN + +$0 will search through the file for words that can be made from +the letters in the list argument. Each letter will only be used once. +EOF + +die $usage unless @ARGV; + +my $list = shift; + +while (<>) { + #remove newline + chomp; + #copy the string to check for letters + my $string = $_; + #remove any letter in our list from the word + $string =~ s/$_// for split //, $list; + #if there's no word left, then print our original word + CORE::say unless $string; +} -- cgit