diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2020-10-09 10:55:06 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2020-10-09 10:55:06 +0200 |
| commit | 973c66cd12ed324880767de16c4788e376ff778f (patch) | |
| tree | 474f9ab00b7c82627bebe2505df57efb2aca6a0e | |
| parent | 68d66b4b6065b686ec7c91ca8c1a72d843a268bc (diff) | |
| download | perlweeklychallenge-club-973c66cd12ed324880767de16c4788e376ff778f.tar.gz perlweeklychallenge-club-973c66cd12ed324880767de16c4788e376ff778f.tar.bz2 perlweeklychallenge-club-973c66cd12ed324880767de16c4788e376ff778f.zip | |
Challenge 081 Task 1 LK Perl
| -rw-r--r-- | challenge-081/lubos-kolouch/perl/ch-1.pl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/challenge-081/lubos-kolouch/perl/ch-1.pl b/challenge-081/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..6aed6bb23b --- /dev/null +++ b/challenge-081/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-1.pl +# +# USAGE: ./ch-1.pl +# +# DESCRIPTION: Perl Weekly Challenge 081 +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/ +# Task 1 - Common base string +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: YOUR NAME (), +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 10/09/2020 10:43:10 AM +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; + + +sub get_common_strings { + my $arg = shift; + + my $str1 = $arg->{str1}; + my $str2 = $arg->{str2}; + + my @result; + + my ($res1) = $str1 =~ /(.*)\1+/; + push @result, $res1; + + my ($res2) = $str2 =~ /(.*)\1+/; + push @result, $res2 unless $res1 eq $res2; + + return \@result; + +} + +use Test::More; + +is_deeply(get_common_strings({str1 => 'abcdabcd', str2 => 'abcdabcdabcdabcd'} ),['abcd','abcdabcd']); +is_deeply(get_common_strings({str1 => 'aaa', str2 => 'aa'} ),['a']); +is_deeply(get_common_strings({str1 => 'abc', str2 => 'aa'} ),['','a']); + |
