aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-275/bob-lied/perl/ch-1.pl4
-rw-r--r--challenge-275/bob-lied/perl/ch-2.pl20
2 files changed, 7 insertions, 17 deletions
diff --git a/challenge-275/bob-lied/perl/ch-1.pl b/challenge-275/bob-lied/perl/ch-1.pl
index 4e996497cb..fef05b2694 100644
--- a/challenge-275/bob-lied/perl/ch-1.pl
+++ b/challenge-275/bob-lied/perl/ch-1.pl
@@ -46,8 +46,8 @@ sub bk($sentence, @keys)
# my $re = '^[^' . join("", @keys) . ']*$';
# return scalar grep /$re/i, split(/\W+/, $sentence);
# my $re = '[' . join("", @keys) . ']';
- local $, = '';
- my $re = qq([@keys]);
+ my $re;
+ { local $, = ''; $re = qq([@keys]); }
my @s = split(/\W+/, $sentence);
return scalar(@s) - ( grep /$re/i, @s );
}
diff --git a/challenge-275/bob-lied/perl/ch-2.pl b/challenge-275/bob-lied/perl/ch-2.pl
index 4c9897fe9e..97019a077f 100644
--- a/challenge-275/bob-lied/perl/ch-2.pl
+++ b/challenge-275/bob-lied/perl/ch-2.pl
@@ -29,22 +29,21 @@ use Getopt::Long;
my $DoTest = false;
my $Benchmark = 0;
-GetOptions("test" => \$DoTest, "benchmark:i" => \$Benchmark);
+GetOptions("test" => \$DoTest);
exit(!runTest()) if $DoTest;
-exit( runBenchmark($Benchmark) ) if $Benchmark;
-# Must begin not begin with a digit
+# Must not begin with a digit
say replaceDigits($_) for map { s/^[0-9]*//ir } @ARGV;
sub replaceDigits($str)
{
my @s = split("", $str);
- my $prev = my $result = shift @s;
+ my $letter = my $result = shift @s;
while ( defined(my $next = shift @s) )
{
- if ( $next =~ m/[^0-9]/i ) { $result .= ($prev = $next) }
- else { $result .= chr(ord($prev) + $next); }
+ if ( $next =~ m/[^0-9]/i ) { $result .= ($letter = $next) }
+ else { $result .= chr(ord($letter) + $next); }
}
return $result;
}
@@ -61,12 +60,3 @@ sub runTest
done_testing;
}
-
-sub runBenchmark($repeat)
-{
- use Benchmark qw/cmpthese/;
-
- cmpthese($repeat, {
- label => sub { },
- });
-}