← All languages
Perl function of the day

uc

Return an uppercased version of a string.

Description

The uc function returns a copy of the string with all characters converted to uppercase. It does not modify the original string. If called without an argument, it operates on $_.

uc respects the current locale if the use locale pragma is in effect. It also handles Unicode characters correctly, converting them according to Unicode case-folding rules.

For uppercasing just the first character of a string, use ucfirst instead. The lc function performs the opposite operation, converting to lowercase.

Arguments

NameDescriptionOptional
EXPR The string to convert to uppercase. Defaults to $_ if omitted. Yes

Example

my $str = 'hello world';
print uc($str);  # HELLO WORLD

print uc('perl');  # PERL

Reference