Perl
  Home arrow Perl arrow Page 4 - Perl Conditionals
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 Conditionals
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2007-10-16


    Table of Contents:
  • Perl Conditionals
  • You Better or Else!
  • The Unless Statement
  • The While Loop

  • 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 Conditionals - The While Loop
    ( Page 4 of 4 )

    The While Loop loops until a condition you give it is false.


    #!/usr/bin/perl


    $count= 1


    while ($count<10)

    {

    print "$countn";

    $count++;

    }

    The above code will, like the code before it, print out the numbers 1 through 9, stopping once the value becomes equal to ten and the statement is false.

    Foreach There is Another!

    Our final Loop is known as the Foreach Loop and is used mostly with arrays.


    #!/usr/bin/perl


    @breakfast = ("Sausage", "Eggs", "Bacon", "Grits", "Toast" "Hash");


    print "My breakfast:nn";


    foreach $breakfast (@breakfast)

    {

    print "$breakfastn";

    }

    This code access the values in your array and prints them one by one:

      Sausage

      Eggs

      Bacon

      Grits

      Toast

      Hash

    And that is it for Loops and Conditionals. In my next tutorial, I will go over a few more statements, and we will learn to work with files -- creating them, reading them, writing them, you name it.

    So go forth, young nerdling, and use your Perl wisdom for great deeds. Till then...



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