perl function uc

https:/‮‬/www.theitroad.com

The uc function in Perl is used to convert a given string to uppercase letters. It takes a string as an argument and returns a new string with all alphabetic characters in uppercase.

Here's an example:

my $str = "hello world";
my $uc_str = uc($str);
print $uc_str;  # output: HELLO WORLD

In this example, we first declare a string variable $str with the value "hello world". We then pass this string to the uc function, which converts all the alphabetic characters in the string to uppercase letters and returns a new string. We store this new string in the variable $uc_str and print it using the print function.

Note that the uc function only affects alphabetic characters in the string, leaving non-alphabetic characters unchanged. If you want to convert the entire string to uppercase, including non-alphabetic characters, you can use the tr function with the A-Z range of characters:

my $str = "hello, world!";
$str =~ tr/a-z/A-Z/;
print $str;  # output: HELLO, WORLD!

In this example, we first declare a string variable $str with the value "hello, world!". We then use the tr function with the a-z and A-Z ranges of characters to convert all alphabetic characters in the string to uppercase. The =~ operator is used to apply this transformation to the string variable itself. We then print the modified string using the print function.