The weekly challenge 311 - Task 1: Upper Lower
1 #!/usr/bin/env perl 2 # https://theweeklychallenge.org/blog/perl-weekly-challenge-311/#TASK1 3 # 4 # Task 1: Upper Lower 5 # =================== 6 # 7 # You are given a string consists of english letters only. 8 # 9 # Write a script to convert lower case to upper and upper case to lower in the 10 # given string. 11 # 12 ## Example 1 13 ## 14 ## Input: $str = "pERl" 15 ## Output: "PerL" 16 # 17 ## Example 2 18 ## 19 ## Input: $str = "rakU" 20 ## Output: "RAKu" 21 # 22 ## Example 3 23 ## 24 ## Input: $str = "PyThOn" 25 ## Output: "pYtHoN" 26 # 27 ############################################################ 28 ## 29 ## discussion 30 ## 31 ############################################################ 32 # 33 # The tr/// operator allows us to swap in one step, so let's 34 # just use that. 35 36 37 use v5.36; 38 39 foreach ( qw(pERl rakU PyThOn) ) { 40 say "Input: $_, Output: " . upper_lower($_); 41 } 42 43 sub upper_lower { 44 my $str = shift; 45 $str =~ tr/a-zA-Z/A-Za-z/; 46 return $str; 47 } 48