Perl
  Home arrow Perl arrow Page 7 - Perl 101 (part 6) - The Perl Toolbox
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl 101 (part 6) - The Perl Toolbox
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2000-08-30

    Table of Contents:
  • Perl 101 (part 6) - The Perl Toolbox
  • Expressing Yourself
  • Engry Young Men
  • Aardvark, Anyone?
  • Needles In Haystacks
  • Slice And Dice
  • Going Backwards
  • Math Class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Perl 101 (part 6) - The Perl Toolbox - Going Backwards
    (Page 7 of 8 )

    The next few string functions come in very handy when adjusting the case of a text string from lower- to upper-case, or vice-versa:
    
    lc($string) - convert $string to lower case
    uc($string) - convert $string to upper case
    lcfirst($string) - convert the first character of $string to lower case
    ucfirst($string) - convert the first character of $string to upper case
    

    Here's an example:
    #!/usr/bin/perl
    # get a string
    print "Say something: ";
    chomp($string = );
    # convert case
    $output= lc($string);
    print "All lower case: $output\n";
    $output= uc($string);
    print "All upper case: $output\n";
    $output= lcfirst($string);
    print "Look at the first character: $output\n";
    $output =  ucfirst($string);
    print "Look at the first character: $output\n";
    

    And here's the output:
    
    Say something: Something's rotten in the state of Denmark
    All lower case: something's rotten in the state of denmark
    All upper case: SOMETHING'S ROTTEN IN THE STATE OF DENMARK
    Look at the first character: something's rotten in the state of Denmark
    Look at the first character: Something's rotten in the state of Denmark
    

    The reverse() function is used to reverse the contents of a particular string.
    #!/usr/bin/perl
    # ask for input
    print "Say something: ";
    $something = ;
    chomp ($something);
    # reverse and print
    $gnithemos = reverse($something);
    print "Sorry, you seem to be talking backwards - what does $gnithemos
    mean?";
    

    Here's the output:
    
    Say something: God, I'm good
    Sorry, you seem to be talking backwards - what does doog m'I ,doG mean?
    

    And the chr() and ord() functions come in handy when converting from ASCII codes to characters and vice-versa. For example,
    
    print chr(65);
    returns
    A
    while
    print ord("a");
    returns
    97
    



    This article copyright Melonfire 2000. All rights reserved.

    More Perl Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway