Perl String lc() Function

How to Use the String lc() Function to Convert a String to Lowercase

Starting out with a new programming language can be challenging. Learning the functions is one way to go about it. The Perl string lc() function and uc() function are two basic functions that are easy to understand—they convert a string to all lowercase or all uppercase respectively.

Perl String lc() Function

The Perl lc() function takes a string, makes the entire thing lowercase and then returns the new string. For example:

#!/usr/bin/perl

$orig_string = "This Test Is Capitalized";

$changed_string = lc( $orig_string );

print "The Resulting String is: $changed_string\n";

When executed, this code yields:

The Resulting String is: this test is capitalized

First, $orig_string is set to a value—in this case, This Test Is Capitalized. Then the lc() function is run on $orig_string. The lc() function takes the entire string $orig_string and converts it to its lowercase equivalent and prints it out as instructed.

Perl String uc() Function

As you might expect, Perl's uc() function converts a string to all uppercase characters in the same manner. Just substitute uc for lc in the example above, as shown:

#!/usr/bin/perl

$orig_string = "This Test Is Capitalized";

$changed_string = uc( $orig_string );

print "The Resulting String is: $changed_string\n";

When executed, this code yields:

The Resulting String is: THIS TEST IS CAPITALIZED

About Perl

Perl is a feature-rich programming language that was originally developed for use with text. It is cross-platform and runs on more than 100 platforms. Perl works with HTML and other markup languages, so it is frequently used in web development. Check out the Perl string length function to do more with strings.

Format
mla apa chicago
Your Citation
Brown, Kirk. "Perl String lc() Function." ThoughtCo, Jan. 29, 2020, thoughtco.com/perl-string-lc-function-quick-tutorial-2641188. Brown, Kirk. (2020, January 29). Perl String lc() Function. Retrieved from https://www.thoughtco.com/perl-string-lc-function-quick-tutorial-2641188 Brown, Kirk. "Perl String lc() Function." ThoughtCo. https://www.thoughtco.com/perl-string-lc-function-quick-tutorial-2641188 (accessed April 20, 2024).