Perl
  Home arrow Perl arrow Page 3 - 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 
IBM Rational Software Development Conference
 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 - 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


       · 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 2 hosted by Hostway