diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-20 22:05:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-20 22:05:36 +0100 |
| commit | 0c2941b1f75db36fc7704d8f08aeab126baacca5 (patch) | |
| tree | dac9326158b0b929890096eea76982d0ce01e47e | |
| parent | 280b3497d5582989fa871877aadac37146473c6e (diff) | |
| parent | 81159ac6575a9104b9d06164f4050cc9530a9058 (diff) | |
| download | perlweeklychallenge-club-0c2941b1f75db36fc7704d8f08aeab126baacca5.tar.gz perlweeklychallenge-club-0c2941b1f75db36fc7704d8f08aeab126baacca5.tar.bz2 perlweeklychallenge-club-0c2941b1f75db36fc7704d8f08aeab126baacca5.zip | |
Merge pull request #4299 from Cris-HD/branch-for-challenge-117
Added challenge 117 solution
| -rwxr-xr-x | challenge-117/cristian-heredia/perl/ch_1.pl | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/challenge-117/cristian-heredia/perl/ch_1.pl b/challenge-117/cristian-heredia/perl/ch_1.pl new file mode 100755 index 0000000000..cd52e9bcd1 --- /dev/null +++ b/challenge-117/cristian-heredia/perl/ch_1.pl @@ -0,0 +1,77 @@ +=begin + +TASK #1 › Missing Row +Submitted by: Mohammad S Anwar +You are given text file with rows numbered 1-15 in random order but there is a catch one row in missing in the file. + +11, Line Eleven +1, Line one +9, Line Nine +13, Line Thirteen +2, Line two +6, Line Six +8, Line Eight +10, Line Ten +7, Line Seven +4, Line Four +14, Line Fourteen +3, Line three +15, Line Fifteen +5, Line Five +Write a script to find the missing row number. + +=end +=cut + +use strict; +use warnings; +use Data::Dumper; + + +my @values; +my @allNumbers = (1 .. 15); + +my %numinwrd = ( + 1 => 'Line One', 2 => 'Line Two', 3 => 'Line Three', 4 => 'Line Four', 5 => 'Line Five', + 6 => 'Line Six', 7 => 'Line Seven', 8 => 'Line Eight', 9 => 'Line Nine', 10 => 'Line Ten', + 11 => 'Line Eleven', 12 => 'Line Twelve', 13 => 'Line Thirteen', 14 => 'Line Fourteen', 15 => 'Line Fifteen' +); + + +readFile(checkFile()); + +sub checkFile{ + my $number_args = $#ARGV + 1; + if ($number_args != 1) { + print "Please enter the name of the file in the command line.\n"; + exit; + } + # if command line argument received, + return $ARGV[0]; +} + +sub readFile { + + my $file = shift; + open(FILE, $file) or die "Could not read from $file\n"; + + while (<FILE>) { + push(@values, split(", ")); + } + for (my $i = 0; $i<@allNumbers;$i++){ + unless ( grep( /^$allNumbers[$i]$/, @values ) ) { + print "The line missing is:\n"; + print "$allNumbers[$i], $numinwrd{$allNumbers[$i]}\n"; + next; + } + } +} + + + + + + + + + |
