-
-
Save adamcrussell/48cb0783c3a812edb448646df0ee96de to your computer and use it in GitHub Desktop.
Perl Weekly Challenge 001
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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