aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-004/lakpatashi/perl/ch-2.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-004/lakpatashi/perl/ch-2.pl b/challenge-004/lakpatashi/perl/ch-2.pl
index e9c43aa4cb..013893f9c2 100755
--- a/challenge-004/lakpatashi/perl/ch-2.pl
+++ b/challenge-004/lakpatashi/perl/ch-2.pl
@@ -1,5 +1,6 @@
#!/usr/bin/perl
+use v5.10;
use strict;
use warnings;
@@ -44,3 +45,28 @@ sub buildFreq{ #given a string returns letter freq. hash
}
return %freq;
}
+
+
+# ------------- version 2 -----------------------
+sub checkWord {
+ my ($word,$letters) = @_;
+ $word = join '\w*', sort split //, lc $word;
+ $letters = join "", sort split //, lc $letters;
+ my $pattern = $word;
+ if( $letters =~ /$pattern/ ){
+ return 1;
+ }else{
+ return 0;
+ }
+}
+
+my $letters = 'aabceilttxyz';
+open(FH, "inputFile") or die "open inputFile:: $!";
+for my $word (<FH>) {
+ chop $word;
+ if( checkWord($word, $letters) ){
+ say "valid: $word";
+ }else{
+ say "not valid: $word"
+ }
+}