Perl uc Function

These sites are FOR SALE: miscperlinfo.com, mpihowto.com!
If you are interested, please use my Contact page.




The Perl uc function (which stands for uppercase) is meant to return a uppercase version of a string expression. Some useful examples of how to use this function in your scripts will be given to you in this tutorial. Click the lc link to see the correspondent lc Perl function which converts a string expression to lowercase characters.

There are two syntax forms for this function:

uc EXPR 
uc

Please note that the Perl uc function doesn’t alter the string variable content, but it returns an uppercase copy of the string. If you omit the EXPR parameter, the Perl uc function will use the content of the special variable $_.


Click Below to See the Best

Perl How-to Snippet Collection

and Save Hours of Surfing on Internet!


Here is an example about how to use it:

# initialize some string variable
my $string = "This is about Perl Functions";
uc($string);
print $string, "\n";
# displays: This is about Perl Functions
$string = uc($string);
print $string, "\n";
# displays: THIS IS ABOUT PERL FUNCTIONS

If we don’t make an assignment for the variable we convert through the uc function, the result of the conversion will be lost – you can see this in the 3-5 lines of the above code. At the end of the code we store the uppercase converted value in the same variable (line 6) and we print it again.

This uc function is very useful when you perform some string comparisons. Try to remember that all comparisons are case sensitive and the following strings "uc" and "UC" are not the same.

Now let’s consider the case insensitive comparison of two strings. You can use the uc function either converting both strings in lowercase using an assignment operator and than make the comparisons or compare the strings by calling the uc function for each of them, without changing their values.

The next short example shows you how to do this:

my $string1 = "blue";
my $string2 = "Blue";
$string1 = uc($string1);
$string2 = uc($string2);
if($string1 eq $string2)	
{
  print "The two strings are equal\n";
}

#comparison without altering the string values

$string1 = "blue";
$string2 = "Blue";
if(uc($string1) eq uc($string2))
{
  print "The two strings are equal\n";
}

Please click here to download the Perl uc script with all the above examples included.

A-N-Y-O-N-E Can Learn and Master Perl!
And That Includes YOU!


Check these how-to tutorial eBooks (PDF format):


Table of Contents:

A Perl Script
Install Perl
Running Perl
Perl Data Types
Perl Variables
Perl Operators
Perl Lists
Perl Arrays
    Array Size
    Array Length
Perl Hashes
Perl Statements
    Perl if
    Perl unless
    Perl switch
    Perl while
    Perl do-while
    Perl until
    Perl do-until
    Perl for
    Perl foreach
Built-in Perl Functions
    Functions by Category
        String Functions
        Regular Expressions and Pattern Matching
        List Functions
        Array Functions
        Hash Functions
        Miscellaneous Functions
    Functions in alphabetical order
        chomp
        chop
        chr
        crypt
        defined
        delete
        each
        exists
        grep
        hex
        index
        join
        keys
        lc
        lcfirst
        length
        map
        oct
        ord
        pack
        pop
        push
        q
        qq
        qw
        reverse
        rindex
        scalar
        shift
        sort
        splice
        split
        sprintf
        substr
        tr
        uc (more)
        ucfirst
        undef
        unpack
        unshift
        values

return from Perl uc Function to Perl Basics



Would you like to create your own website like this one?
Hit the Alarm Clock!

Site Build It!