Perl
  Home arrow Perl arrow Page 2 - Perl: Concatenating Text and More
FaxWave - Free Trial.
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: Concatenating Text and More
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-03-10

    Table of Contents:
  • Perl: Concatenating Text and More
  • Making Copies
  • Chomping It Up Pac-Man Style
  • Transformers...More than Meets the Eye

  • 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

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Help Simplify Virtualization by IBM

    Perl: Concatenating Text and More - Making Copies
    (Page 2 of 4 )

    If we want to repeat a string a bunch of times, we can do so by multiplying it. Let's say I walk into a wrestling arena and am fighting the Badass Bulgarian. Here is a program that demonstrates what the crowd might say, if they know what is good for them:


    #!/usr/bin/perl

     

    $chant="USA! ";

    $chantTwo="Bulgaria blows! ";

    $chantThree="James Payne! ";

    print $chant x 10;

    print "\n" . $chantTwo x 10;

    print "\n" . $chantThree x 10;

    This results in:

    USA! USA! USA! USA! USA! USA! USA! USA! USA! USA!

    Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows! Bulgaria blows!

    James Payne! James Payne! James Payne! James Payne! James Payne! James Payne! James Payne! James Payne! James Payne! James Payne!

    But what if we wanted to not have the words listed on the same line?


    #!/usr/bin/perl

     

    $chant="\tUSA! \n";

    $chantTwo="\tBulgaria blows! ";

    $chantThree="James Payne! ";

    print $chant x 10;

    This prints the variable $chant 10 times, skipping a line and adding a tab at the beginning of each new line, resulting in the following:

    USA!

    USA!

    USA!

    USA!

    USA!

    USA!

    USA!

    USA!

    USA!

    USA!

    More Perl Articles
    More By James Payne


       · Hi, thanks for droppingby to read my Perl article. Inside we discuss how to...
     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - 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




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