Perl
  Home arrow Perl arrow Perl Conditionals
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 
OLM
 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 Conditionals
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 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:
      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

    Lose your application development headaches. Start developing and deploying applications with Advantage Database Server today. Download a 30-day trial for Free!

    Perl Conditionals
    (Page 1 of 4 )

    While Perl truly is the programming language of the slacker, the bored, and the (okay I'll say it with great lamentation) creative, it is also a harsh mistress. But let's face it: as a computer programmer, you are luck to have a mistress at all. So chin up. Perl doesn't just freely give you love. There are conditions, or, more precisely, conditionals, which is the topic of this fourth part in a series.

    Sure, in the beginning, when you are learning syntax and how to print My cat is named Darth Fluffymittens, Perl is nice and easy, ready to go anytime you are. But as soon as you get to the part about Conditionals...bam! Marriage over.

    Maybe I have written too many articles on conditionals; if there is a programming language, you can rest assured I told someone how to write conditionals in it. Maybe I am jaded. Perl conditionals, I have to admit though, are very simple once you grasp the concept.

    So put on your safety gloves and let's get to grasping.

    Conditional Lovin'

    Conditionals are statements written in code that ask a question, and then respond accordingly to the answer. A good way to think of a conditional is to think about yourself when a bill is overdue. Yeah you slacker, I know all about your late bills.

    In pseudo code (or fake code), the situation would look like this:


    If


    I pay bill


    Then lights stay on


    End

    The above is an example of an If-statement. Simply put, do this, and this happens. Now let's see the same situation in real code:


    #!/usr/bin/perl


    $your_money = 0;


    if ($your_money < 1) #asks if your money is less than 1


    {

    print "You are broke!"; #if it is, print "You are broke"

    }


    print "Your lights might be shut off!";

    The above code asks if you have less than a dollar. If the answer is yes (which it is), then the program prints: "You are broke!". The last line: "Your lights might be shut off!" prints regardless of the conditional, as it is outside of the statement.

    If the value of $your_money was greater than 1, the program would have skipped the "You are broke!" line but still printed the "Your lights might be shut off!" sentence.

    More Perl Articles
    More By James Payne


       · In this episode I discuss conditionals within Perl, as well as the While loop and...
     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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