Perl
  Home arrow Perl arrow Page 3 - 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 - Printing Variables
    ( Page 3 of 4 )

    We've learned in the past to work with variables, and I know this is a bit redundant, but keep in mind that this article is more of a cheat sheet for different ways of manipulating text.

    We store text in variables and print it like so: 

    !/usr/bin/perl

    $a='Apple';

    $b='Jacks';

    print "The best cereal in the world is $a $b.";

    This prints out:


      The best cereal in the world is Apple Jacks.

    One note of warning: in the previous section we talked about using single and double quotes together. This method does not work the same when dealing with variables. Observe the following:


    #!/usr/bin/perl

    $a='apple';

    $b='jacks';

    print 'The best cereal in the world is $a $b.';

    This will print out:

      The best cereal in the world is $a $b.

    Which of course is not what we were hoping for.

    To get it to print the values inside the variables, we have to use double quotes, like so:


    #!/usr/bin/perl

    $a='Apple';

    $b='Jacks';

    print "The best cereal in the world is $a $b.";

    Which results in the proper print-out (and a very true statement):

      The best cereal in the world is Apple Jacks.

    The reason why this occurs is simple enough. When Perl sees a single quotation mark, it does not interpret; when it sees double quotation marks, it does.

    Note that you can store an unlimited amount of variables within your double quoted string:


    #!/usr/bin/perl

    $a="Hello";

    $b="how";

    $c="are";

    $d="you";

    $e="doing";

    $f="today?";

    $Question="$a $b $c $d $e $f";

    print $Question;

    Which gives us:

      Hello how are you doing today?



     
     
    >>> 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek