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.

  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



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:





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:







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





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 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 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: