From 2a8ab77ad792fe660dfb59972e7fb7abe7939e36 Mon Sep 17 00:00:00 2001 From: boblied Date: Sun, 21 Feb 2021 15:48:45 -0600 Subject: PWC 001 Solutions --- challenge-001/bob-lied/perl/ch-1.pl | 23 +++++++++++++++++++++++ challenge-001/bob-lied/perl/ch-2.pl | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 challenge-001/bob-lied/perl/ch-1.pl create mode 100755 challenge-001/bob-lied/perl/ch-2.pl diff --git a/challenge-001/bob-lied/perl/ch-1.pl b/challenge-001/bob-lied/perl/ch-1.pl new file mode 100755 index 0000000000..ea9e3ff4f4 --- /dev/null +++ b/challenge-001/bob-lied/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-1.pl +#============================================================================= +# Copyright (c) 2021, Bob Lied +#============================================================================= +# Perl Weekly Challenge 001, Task #1 Replace with E +# Write a script to replace the character ‘e’ with ‘E’ in the string +# ‘Perl Weekly Challenge’. +# Also print the number of times the character ‘e’ is found in the string. +#============================================================================= + +use strict; +use warnings; +use 5.020; + +my $s = 'Perl Weekly Challenge'; + +my $count = $s =~ tr/e/E/; + +say $s; +say $count; diff --git a/challenge-001/bob-lied/perl/ch-2.pl b/challenge-001/bob-lied/perl/ch-2.pl new file mode 100755 index 0000000000..e09e349dd1 --- /dev/null +++ b/challenge-001/bob-lied/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-2.pl +#============================================================================= +# Copyright (c) 2021, Bob Lied +#============================================================================= +# Perl Weekly Challenge 001, Task #2 FizzBuzz +# Write a one-liner to solve the FizzBuzz problem and print the numbers 1 +# through 20. However, any number divisible by 3 should be replaced by the +# word ‘fizz’ and any divisible by 5 by the word ‘buzz’. Those numbers that +# are both divisible by 3 and 5 become ‘fizzbuzz’. +#============================================================================= + +use strict; +use warnings; +use 5.020; + +say ($_%15==0 ? 'fizzbuzz' : $_%5==0 ? 'buzz' : $_%3==0 ? 'fizz' : $_) foreach 1..20 -- cgit