Perl String lc() Function

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

Format
mla apa chicago
Your Citation
Brown, Kirk. "Perl String lc() Function." ThoughtCo, Dec. 5, 2016, thoughtco.com/perl-string-lc-function-quick-tutorial-2641188. Brown, Kirk. (2016, December 5). 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 September 20, 2017).

Starting out with a new programming language can be challenging. Learning the functions is one way to go about it. The Per;l 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. 

Format
mla apa chicago
Your Citation
Brown, Kirk. "Perl String lc() Function." ThoughtCo, Dec. 5, 2016, thoughtco.com/perl-string-lc-function-quick-tutorial-2641188. Brown, Kirk. (2016, December 5). 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 September 20, 2017).