Home
FREE Newsletter
Perl How To
Perl Books
Perl Basics
Perl Editors
Perl Modules
Perl Database
Net Programming
Sitemap
About Me
Contact Me
Blog
 

Perl uc Function



NEW!!!

Check my new resource:    Perl How To Tutorial eBooks



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 $_.


Check my new How To Tutorial eBooks (PDF format):

to see a lot of fully commented examples that help you use the Perl statements and the Perl buit-in functions in your scripts.



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. We can use the uc function either converting both strings in lowercases 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.



Subscribe now to my FREE newsletter
(regarding tips and tricks to manipulate multidimensional
arrays and hashes in Perl)

and you'll receive a link to download for FREE my Perl chomp Function Tutorial eBook (a $7.50 value), it's a bonus for you and I hope you'll enjoy it. You can see its Table of Contents here (if you subscribe to my free newsletter, you don't have to pay for this eBook or use your paypal account).




NEW!!!

Do you want more information about the basic Perl topics?

Check my new "Perl How To" Tutorial eBooks page where I'll answer the most frequent questions regarding some topics :


Perl How To Tutorial eBooks


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
        Array Functions
    Functions in alphabetical order
        chomp
        chop
        chr
        crypt
        defined
        grep
        hex
        index
        join
        lc
        lcfirst
        length
        map
        oct
        ord
        pack
        pop
        push
        qw
        reverse
        rindex
        scalar
        shift
        sort
        splice
        split
        substr
        uc
        undef
        unshift

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!


footer for perl uc page