Home arrow Perl Programming arrow Page 4 - Perl: Releasing Your Inner Textuality

More Printing Information - Perl

There are lots of way to express yourself, but with programming languages the simplest way to do that is usually text. This tutorial will walk you through ways to make text work for you in Perl. It's the first of a three-part series, and since (as usual) we have a lot of ground to cover, let's get started.

TABLE OF CONTENTS:
  1. Perl: Releasing Your Inner Textuality
  2. Special Characters Don't Need Helmets or Small Buses
  3. Printing Variables
  4. More Printing Information
By: James Payne
Rating: starstarstarstarstar / 1
February 25, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Another thing to keep in mind is that you must use a backslash to print a $ symbol. Without it, Perl will try to interpret it as a variable. Behold:


#!/usr/bin/perl

print "I have $15.00 in my pocket boyee!";

If you try to run that program you will get an odd result:

  I have .00 in my pocket boyee!

Very odd indeed. Since we aren't trying to print a variable, the proper way to write this code would be:


#!/usr/bin/perl

print "I have \$15.00 in my pocket boyee!";

Which would give us the correct print out of:

  I have $15.00 in my pocket boyee!

Similarly, you cannot print out an @ symbol either. The following will not work:


#!/usr/bin/perl

print "My email address is james@james.com.";

If you used this code it would print:

  My email address is james.com.

To fix this, we again use our good old buddy the backslash:


#!/usr/bin/perl

print "My email address is james\@james.com.";

Which prints out:

  My email address is james@james.com .

And lastly, we can also use escape characters and special characters on our variables. Here is an example:


#!/usr/bin/perl

$color="black";

$number="eight";

print "\n\nPlease find my favorite color and number below:\n\n";

print "\tMy favorite color:\t\t\t$color\n";

print "\tMy favorite number is:\t\t\t$number\n\n";

This will print out our text and variables so that they appear like this on the user's screen:

  Please find my favorite color and number below"


  My favorite color:               black

  My favorite number is:       eight

Well that's all the time we have for this exciting episode. Join us next time when we continue this intriguing, gut wrenching discussion on Perl text manipulation. I look forward to seeing you.

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: