Skip to content

Instantly share code, notes, and snippets.

@adamcrussell
Created April 2, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcrussell/48cb0783c3a812edb448646df0ee96de to your computer and use it in GitHub Desktop.
Save adamcrussell/48cb0783c3a812edb448646df0ee96de to your computer and use it in GitHub Desktop.
Perl Weekly Challenge 001
use strict;
use warnings;
##
# Challenge #1
# 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.
##
my $challenge_string="Perl Weekly Challenge";
my $number=do{
$challenge_string=~tr/e/E/
};
print "$number $challenge_string\n";
use strict;
use warnings;
##
# Challenge #2
# Write one-liner to solve FizzBuzz problem and print number 1-20.
# However, any number divisible by 3 should be replaced by the word fizz
# and any divisible by 5 by the word buzz. Numbers divisible by both become fizz buzz.
##
use experimental q/switch/;
my $i = 1;
{
given($i){
when($i % 3 == 0 && $i % 5 == 0){
print "fizz buzz\n";
}
when($i % 5 == 0){
print "buzz\n";
}
when($i % 3 == 0){
print "fizz\n";
}
default{
print "$i\n";
}
}
$i++;
redo until ($i > 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment