Home arrow Perl Programming arrow Page 4 - Perl: Concatenating Text and More

Transformers...More than Meets the Eye - Perl

This marks the finale of our coverage of text in Perl (until we get into some more of the advanced Perl features at any rate). We left off with the here document and how to use it to display text exactly as we type it in, using a Mark Twain poem that he had written for his daughter's tombstone (which interestingly enough was a rewrite of another poet's poem). We also learned a little bit about ASCII and the values as they pertain to text, showcasing the 93 visible characters.

TABLE OF CONTENTS:
  1. Perl: Concatenating Text and More
  2. Making Copies
  3. Chomping It Up Pac-Man Style
  4. Transformers...More than Meets the Eye
By: James Payne
Rating: starstarstarstarstar / 5
March 10, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

There are a number of built-in Perl functions that allow you to do crazy things with text. Among those are ways to manipulate the case of characters, changing the first letter to upper/lower case, the whole string to upper/lower case, etc. Here they are in a program:


#!/usr/bin/perl

 

$thingOne="james";

$thingtwo="PAYNE";

print $thingOne . "\n";

print ucfirst($thingOne);

print "\n";

print uc($thingOne);

print "\n\n";

print $thingtwo;

print "\n";

print lcfirst($thingtwo);

print "\n";

print lc($thingtwo);

This will result in:

  james

  James

  JAMES


  PAYNE

  pAYNE

  payne

If functions aren't your thing, you can also use special characters to achieve the same effect:


#!/usr/bin/perl

 

$thingOne="james";

$thingtwo="PAYNE";

print "l$thingtwo";

print "\n\n";

print "u$thingOne";

print "\n\n";

print "L$thingtwo IS MY LAST NAME E U$thingOneE is the first.";

This gives us the result:

  pAyne

  James

  payne is my last name JAMES is the first.

A few things to note: the "l" and "u" act as lcfirst and ucfirst, respectively, while the "L" and "U" make everything following it uppercase until it reaches the "E", which signals an end to the special character.

Well unfortunately we did not get to cover every bit of string manipulation that I wanted to, but never fear: we'll get to that in another article. Maybe even the next one, where I will also cover ways to manipulate numbers.

Till then...



 
 
>>> More Perl Programming Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: