I'm trying to write a script which will convert all letters from lowercase to uppercase without using the uc()
function.
Asked
Active
Viewed 8,144 times
-4
-
1Does it need to work with Unicode? – Bribles Jan 17 '13 at 15:31
-
7Why would you want to do that in the first place? – Zaid Jan 17 '13 at 15:38
-
1What's wrong with `uc` that it needs to be avoided? – ikegami Jan 17 '13 at 20:08
2 Answers
6
You could use something like $str =~ tr/a-z/A-Z/
, but uc
is probably better for Unicode support, if it matters to you.

dbrobins
- 499
- 1
- 3
- 9
5
Using regular expressions:
$str =~ s/(.)/\u$1/g;

Sean Bright
- 118,630
- 17
- 138
- 146
-
-
1`\u` is "uppercase the next character" and the substitution is run for each character. – Sean Bright Jan 17 '13 at 16:51
-
1