Perl
  Home arrow Perl arrow Page 2 - Perl: Releasing Your Inner Textuality
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PERL

Perl: Releasing Your Inner Textuality
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek