Task 1: Replace e with E
"The Great Letter Swap: When e Goes Uppercase!"
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.
The Strategy: Simply count the occurrences of 'e' using regex, then perform a global substitution replacing 'e' with 'E'. Return both the count and modified string.
Perl Implementation
sub replace_e {
my $what = shift;
my $count = () = $what =~ /e/g;
$what =~ s/e/E/g;
return [$count, $what];
}
Python Implementation
def replace_e(what: str) -> tuple[int, str]:
count = what.count("e")
modified_what = what.replace("e", "E")
return count, modified_what