diff options
| author | Jose Luis Perez Diez <jluis@escomposlinux.org> | 2020-10-07 19:35:20 +0200 |
|---|---|---|
| committer | Jose Luis Perez Diez <jluis@escomposlinux.org> | 2020-10-07 19:35:20 +0200 |
| commit | c65c694f21ce314c2a47e9a0bf5b4d3a0c993cb4 (patch) | |
| tree | 04711f65599c159517ba13d4f33fc06463b8489f | |
| parent | 347371e27ff3dd862b942ed73a867473b3bedb3a (diff) | |
| download | perlweeklychallenge-club-c65c694f21ce314c2a47e9a0bf5b4d3a0c993cb4.tar.gz perlweeklychallenge-club-c65c694f21ce314c2a47e9a0bf5b4d3a0c993cb4.tar.bz2 perlweeklychallenge-club-c65c694f21ce314c2a47e9a0bf5b4d3a0c993cb4.zip | |
Add usage information
| -rwxr-xr-x[-rw-r--r--] | challenge-081/jluis/perl/ch-1.pl | 25 | ||||
| -rwxr-xr-x[-rw-r--r--] | challenge-081/jluis/perl/ch-2.pl | 9 |
2 files changed, 29 insertions, 5 deletions
diff --git a/challenge-081/jluis/perl/ch-1.pl b/challenge-081/jluis/perl/ch-1.pl index 8549a26895..0563d11964 100644..100755 --- a/challenge-081/jluis/perl/ch-1.pl +++ b/challenge-081/jluis/perl/ch-1.pl @@ -2,12 +2,29 @@ use strict; use warnings; +use 5.010; + +if ($#ARGV != 1) { + say <<USAGE; + + Returns the comon base strigs + Base strings are those that can generte the original by repetition + + ch-1.pl "aaaa" "aaaaaaaaaaaa" + + returns ("a","aa","aa") the commom bases for the two strings +USAGE + exit; +} +my ($A,$B) = @ARGV; + +say format_list( common_base($A,$B) ); sub base { - # bassed on Abigil's prime number regex + # bassed on Abigail's prime number regex # get all base strings of $_[0] # a base string is one that concateneted 0 or more times can generate - # the original string + # the original string my $orig = shift; my @bases; my $length = 1; @@ -23,7 +40,7 @@ sub format_list { my $out = "("; while (my $val = shift) { $out .= '"'.$val.'"'; - $out .= ',' if defined @_[0]; + $out .= ',' if defined $_[0]; } return "$out)"; } @@ -34,6 +51,7 @@ sub common_base { my @result; my $AIndex = 0; my $BIndex = 0; + #Both arrays are ordered by the length of its strings while ($AIndex <= $#A and $BIndex <= $#B) { if ($A[$AIndex] eq $B[$BIndex]) { push @result,$A[$AIndex]; @@ -50,4 +68,3 @@ sub common_base { } return @result; } -CORE::say format_list common_base 'aa'x210,'a'x105; diff --git a/challenge-081/jluis/perl/ch-2.pl b/challenge-081/jluis/perl/ch-2.pl index 010b34985f..a06a666220 100644..100755 --- a/challenge-081/jluis/perl/ch-2.pl +++ b/challenge-081/jluis/perl/ch-2.pl @@ -1,6 +1,13 @@ +#!/usr/bin/env perl use strict; use warnings; use 5.010; +say(<<USAGE) and exit if @ARGV; +finds the frequency of all the words of input + +ch-2.pl must be called without any parameters it operates on a file caled input on the current dir + +USAGE open(my $input,'<','input') or die "Can't open input: $!"; @@ -8,7 +15,7 @@ my %freq; while(<$input>){ chomp; s/\.|"|\(|\)|,|'s|--/ /g; - while (s/\s*(\w+)\s*//) { + while (/(\w+)/g) { $freq{$1} = 0 unless defined $freq{$1}; $freq{$1} += 1; } |
