Perl
  Home arrow Perl arrow Page 2 - Perl: Releasing Your Inner Textuality
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 
 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: Releasing Your Inner Textuality
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-25

    Table of Contents:
  • Perl: Releasing Your Inner Textuality
  • Special Characters Don't Need Helmets or Small Buses
  • Printing Variables
  • More Printing Information

  • 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

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Perl: Releasing Your Inner Textuality - Special Characters Don't Need Helmets or Small Buses
    (Page 2 of 4 )

    Special characters are preceded by a backslash() and allow you to insert what are normally "invisible" characters into your program. Sort of like Frodo when he put on the ring, only you wouldn't think about kicking puppies or slapping ugly babies like he did. You would actually do it.

    Here is a nifty table of special characters and what they do:


    Special Character

    What It Does

    \n

    Creates a newline

    \r

    Creates a carriage return (enter)

    \t

    Creates a tab

    \f

    Creates a formfeed

    \a

    Creates a beep

    \b

    Creates a backspace

    \e

    Creates an Escape

    \v

    Creates a vertical tab

    \\ 

    Displays a backslash

    \'

    Displays a single quote

    "

    Displays a double quote

    So let's go ahead and rewrite our previous code using some of the special characters to give it a more appealing feel:


    #!/usr/bin/perl

    print "\nMy name is James Payne.\n";

    print "I am the world's fattest man.\n\n";

    print "My weight is equivalent to that of 17 suns.\n";

    print "Or 17 of Oprah's sons. You pick.\n";

    print 102;

    print "\n102\n";

    print 10+2;

    print "\t\t\t\t\t10+2";

    This results in:

      My name is James Payne.

      I am the world's fattest man.

     

      My weight is equivalent to that of 17 suns.

      Or 17 of Oprah's sons. You pick.

      102

     

      102

     

      12                     10+2

    We might also wish to use an escape if we want to print double and single quotes, or backslashes. Try the following code:


    #!/usr/bin/perl

    print "And then he said, "How are you?" ";

    print 'And I said, 'Fine, fine' ';

    As you can see, this returns an error message (well two really). To fix this, we can use an escape character, like so:


    #!/usr/bin/perl

    print "And then he said, "How are you?" ";

    print 'And I said, \'Fine, fine.\' ';

    Which results in:

      And then he said, "How are you?" And I said, 'Fine, fine.'

    There is another way to fix this problem if you do not feel like using an escape character. And that is to interchange your single and double quotes, as in the following code:

    #!/usr/bin/perl

    print "And then he said, 'How are you' ";

    print 'And I said, "Fine, fine." ';

    Which gives us the same result as before, or:

    And then he said, "How are you?" And I said, 'Fine, fine.'

    Lastly, if we want to print a backslash, it will not work if we type this:


    #!/usr/bin/perl

    print "Look at my fine backslash:\ ";

    However it will work if we type this:


    #!/usr/bin/perl

    print "Look at my fine backslash:\\ ";

    More Perl Articles
    More By James Payne


       · Thank you for dropping by to read my article on working with Perl Text. This is the...
       · In your second example you missed your backslash.print "My email address is...
       · Hey thanks for catching that; our CMS gobbles up the backslashes sometimes. I'll be...
       · Nice article for beginners, but in the example with the $ you're missing the...
       · Hey, thanks for the comment, and for catching that missing backslash. The CMS we use...
     

       

    PERL ARTICLES

    - 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
    - Perl: Releasing Your Inner Textuality




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